Thank you for your combined help.
It turns out to be a mixture of several things.
1.) By writing to a log file, I could confirm that you need to put conftest.py into the src directory in order to get it appended to the path.
2.) There should be no __init__.py
files in the /project/tests/ subdirectories that have equal names to the subdirectories under /project/src. This is because the /tests/ subdirectories come before the /src/ subdirectories in the list of sys.path. Thus, pytest will recognize directories under /tests first - and if they have an __init__.py
file, assume they are the modules/packages you are looking for. Maybe renaming those directories to "tests/test_module" instead of "tests/module" might help here. Note that this especially applies to the directory in which you have your test_xy.py files.
3.) Finally, you should not use python3 -m pytest tests
but python3 -m pytest
instead, so that the current directory is the starting point, giving pytest the chance to locate conftest.py in the src directory.
Maybe it makes even sense to not have the same names for packages under tests like under source if - for some reason - you need __init__.py
files in them. You could call them test_package, for example.
Honestly, I do wonder why this has never been investigated. As you pointed out, there have been tons of discussions about that. Everyone contributed a little bit. But none was comprehensive. So how do people work in practice? I mean we speak of testing essentials after all.
In all fairness, I also learned from the documentation of pytest that you should build your package properly with a setup.py file instead.
Wow, what a journey. I hope others may benefit. And I thank you all for helping me out.