Replies: 1 comment
-
One year later, I'm still relying on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Quite recently I started to get some errors from VSCode failing at discovering my tests because of something like this:
I'm using a src layout with tests in their own folder looking like this:
My pytest config is the following:
If I remove the
--import-mode=importlib
the discovery is working back again.If I execute the tests using
python -m pytest
switch, tests are running fine as wellFrom what I understand, when running
pytest
directy withimportlib
import mode, pytest does not add thetests
folder in the path causing that error.At the moment my question is more: What is the best/recommended way for importing helpers inside our tests considering:
append
feels to not be the solution as it is recommended to useimportlib
python -m pytest
can not be done through VSCode python extension which use a custom script to discover tests:2023-08-02 18:11:41.126 [info] > .\.venv\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2023.12.0\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir . -s --cache-clear .
so I loose VSCode support for running my testssys.path.append(...)
to add my helpers seems terrible (no type checking, lot of chances to broke this on file changes ...)from tests.helpers import ...
tofrom .helpers import ...
orfrom helpers import ...
does not work either__init__.py
in tests folder is problematic because I can import my test code inside my production code__init__.py
fromtests
folder and putting my helpers inside atests/helpers/__init__.py
does not work either using all kind of impots I could dofrom .helpers ...
from helpers ...
from tests.helpers ...
Thank you for your help ;)
Beta Was this translation helpful? Give feedback.
All reactions