我有一些测试数据用于 pytest 的单元测试。我用环境变量设置了它们的位置。查看我的 pytest 日志,构建会看到环境变量,但它们引用的位置不存在。在 GitHub Actions 文档中,存储库应位于 /home/runner/Repo/ 中。下面是我的文件夹结构。有人看到任何明显的问题吗?
Repo/
notebooks/
repo/
__init__.py
tests/
tests_db.hdf5
Sample_Raw/
...
__init__.py
test_obj1.py
test_obj2.py
obj1.py
obj2.py
utils.py
构建yaml
name: build-test
on:
push:
branches:
- '*' # all branches for now
jobs:
build-and-run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Generate coverage report
env:
DB_URL: /home/runner/work/Repo/repo/tests/test_db.hdf5
RAW_FOLDER: /home/runner/work/Repo/repo/tests/Sample_Raw/
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
name: codecov-umbrella
您可以使用一些众所周知的变量来确保您的工作流程始终能够找到正确的文件夹,无论它在哪个运行器上运行。
存储库根目录可以在以下位置找到${{ github.workspace }}
:
DB_URL: ${{ github.workspace }}/repo/tests/test_db.hdf5
See:
- https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
- https://docs.github.com/en/actions/learn-github-actions/contexts https://docs.github.com/en/actions/learn-github-actions/contexts
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)