Imagine a simple folder structure:
my_folder/
__init__.py
funcs.py
tests/
test_funcs.py
funcs.py:
def f():
return 2
__init__.py:
from funcs import f
test_funcs.py:
from funcs import f
def test_f():
assert f() == 2
It's one of the suggested ways in the documentation: https://pytest.readthedocs.io/en/reorganize-docs/new-docs/user/directory_structure.html
But when I run pytest from my_folder
:
tests/test_funcs.py:1: in <module>
from funcs import f
E ModuleNotFoundError: No module named 'funcs'
It's strange because I would have thought that pytest
sets the path from where it's been running so those kinds of errors don't come up without dealing with it manually.
The documentation doesn't gave any indication about this either... They're just saying :
Typically you can run tests by pointing to test directories or modules:
pytest tests/test_appmodule.py # for external test dirs pytest src/tests/test_appmodule.py # for inlined test dirs pytest src # run tests in all below test directories pytest # run all tests below current dir
What am I missing?