-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
The --import-mode=importlib mode does not change sys.path in order to import test modules and conftest.py files, which has many benefits but also some drawbacks.
Often in test suites there are functions and classes used only for testing. This is not a problem when the tests are embedded in the source, but for layouts where the tests are in a separate directory, users don't have many options where to put those testing-only functions/classes in a way that is importable when using --import-mode=importlib (see #7245 (comment)).
One solution might be to have a new option that appends one or more directories to sys.path when running the tests only:
[pytest]
addopts = --import-mode=importlib
sys_path_append = testsThis at first might seem similar to just going ahead and using --import-mode=append, however this has the advantage that any directory can be added, instead of sys.path being implicitly changed just because tests/conftest.py exists with --import-mode=append.
This is just an idea, opening this issue to discuss the problem of how can we import testing utilities when using imporlib mode in layouts where tests are outside the source code.