Home > Mobile >  How to organise test files for unit testing in Python with sub folders
How to organise test files for unit testing in Python with sub folders

Time:03-18

I was wondering how I can setup my directory structure to enable importing any python file from project in the tests directory to test it?

Currently I'm getting a Module not found error when trying to import a class from some_file.py in some_file_tests.py.

Traceback (most recent call last):
  File "e:\Documents\GitHub\Project\tests\util\some_file_test.py", line 3, in <module>
    from project.util.some_file import SomeFile
ModuleNotFoundError: No module named 'project'

tests/util.some_file_test.py

from project.util.some_file import SomeClass

Here is the directory structure

           
  • Related