6

I have some test data that I use for unit tests with pytest. I set their location with environment variables. Looking at my pytest logs the build sees the environment vars but the locations they reference don't exist. In the GitHub Actions docs the repo should be in /home/runner/Repo/. Below is my folder structure. Anyone see any obvious issues?

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

build 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
pmdaly
  • 1,142
  • 2
  • 21
  • 35

1 Answers1

1

There are wellknown variables that you can use to ensure your workflow can always find the correct folder, no matter what runner it runs on.

The repository root can be found in ${{ github.workspace }}:

DB_URL: ${{ github.workspace }}/repo/tests/test_db.hdf5

See:

jessehouwing
  • 106,458
  • 22
  • 256
  • 341