0

I have a somewhat small project, I broke my project up into different directories to help manage all my files. I am getting around to testing everything right now with pytest and everything runs fine on pycharm. My issue is when uploading this to github actions I get a dreaded ModuleNotFoundError: No module... error. Again all of my tests run in my IDE just not github actions. This is what my import looks like:

from helper_functions import typechecking

def test_force_caps():
  test_string = "i'm a test"
  output = typechecking.force_caps(test_string)
  assert output == "I'M A TEST"
  assert len(output) == 10

My file structure is such:

project
-helper_functions # (directory)
--typechecking.py
-test # (directory)
--test_typechecking.py
-main.py

Every time I run this with github action I get:

______ ERROR collecting tests/helper_function_tests/test_typechecking.py _______ ImportError while importing test module '/home/runner/work/Inventory_db/Inventory_db/tests/helper_function_tests/test_typechecking.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/importlib/init.py:126: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/helper_function_tests/test_typechecking.py:2: in from helper_functions import typechecking E ModuleNotFoundError: No module named 'helper_functions'

I saw a lot of Q and A say to add these to the system path, but found it strange that mine was working just fine, just not through github actions. Do I still need to add it to the path? How do I add it to a path? I tried some solutions but get flake 8 errors and they didn't solve the issue on github actions. Do I simply not test with github actions because they work through pycharm? Is my issue actually with my yaml file?

  • Do you have an `__init__.py` file in the `helper_functions` directory? – GuiFalourd Aug 23 '22 at 11:41
  • @GuiFalourd I do not, should I? Unfortunately we didn't go over this kind of stuff at school the only directory we ever made was one for tests and I guess the reason for why not is because there are some nuances to it. – Robert Munroe Aug 23 '22 at 13:08
  • 1
    I just added an __init__.py to that directory and that didn't solve my issue, although it did become a package instead of a directory. I also added one to my root which didn't solve it either. I saw here: (https://stackoverflow.com/questions/448271/what-is-init-py-for) that __init__.py has become obsolete now, but I tried it anyway. – Robert Munroe Aug 23 '22 at 13:19
  • Look at the run configuration for the tests and check what the working directory is set to. It's probable that PyCharm is running the tests in a different working directory to github. – aml Aug 23 '22 at 14:44
  • 1
    If you are comfortable sharing your yaml file it would be easier to see if there is an issue with it. – aml Aug 23 '22 at 14:48

0 Answers0