pytest cannot find module [duplicate]
Just put an empty conftest.py
file in the project root directory:
$ pwd/home/usr/tmp/junk$ touch conftest.py
Your project structure should become:
junk├── conftest.py├── junk│ ├── __init__.py│ └── ook.py└── tests └── test_ook.py
What happens here: when pytest
discovers a conftest.py
, it modifies sys.path
so it can import stuff from the conftest module. So, since now an empty conftest.py
is found in rootdir, pytest
will be forced to append it to sys.path
. The side effect of this is that your junk
module becomes importable.
Simply add __init__.py
to the tests
directory, and to all directories recursively inside it that contain test files.