I have a python project with working code in a src module and unit tests in another module. When I run the unit test using Visual Studio code on my local workstation, the tests run fine. However, when I check the code into GitHib and use a GitHub action, the unit test cannot find the src directory with the needed modules. I have tried different configurations on the .yml file but nothing has worked so far.
Here is the .yml
jobs:
on_build_actions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: src
- name: Run Tests
run: python -m unittest test_hypedsearch
working-directory: test
Here is the error
Run python -m unittest test_hypedsearch E ====================================================================== ERROR: test_hypedsearch (unittest.loader._FailedTest) ---------------------------------------------------------------------- ImportError: Failed to import test module: test_hypedsearch Traceback (most recent call last): File "/usr/lib/python3.8/unittest/loader.py", line 154, in loadTestsFromName module = import(module_name) File "/home/runner/work/hypedsearch/hypedsearch/test/test_hypedsearch.py", line 5, in from src import runner, utils, database, objects ModuleNotFoundError: No module named 'src'
and here is the top of the unit test code that is throwing the error:
import sys, os.path
import unittest
src_path = (os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + '/src/')
sys.path.append(src_path)
from src import runner, utils, database, objects
Do I need to add a different reference on github to point to the src folder? Here is the directory outline:
