Python3.6 error: ModuleNotFoundError: No module named 'src'

You have to run the test from the my-project folder, rather than from the test folder.

python -m unittest test.test_file1.TestWriteDataBRToOS

This is because it is not able to locate the module named 'src' probably because the path to the 'src' folder isn't specified correctly. If you directly write src.file1, then your 'src' file should be present in the same directory in which your current python file(test_file1.py) is located. If it isn't in the same directory, then you have to specify the entire directory. The reason why sys.path.insert(0, '../src') worked is because .. will move you up one directory and that's where your src folder might be. If your working directory for test_file1.py is /usr/bin/python then the location of your src folder would be /usr/bin/src and since it isn't the same as your current working directory, the python file is not able to locate the 'src' module.


Also you can you do:

export PYTHONPATH="${PYTHONPATH}:/path/to/your/project/"

or in Windows:

set PYTHONPATH="${PYTHONPATH}:/path/to/your/project/"