Open gsnedders opened 4 months ago
Note that prepend
works if we add __init__.py
files all the way up, because we then end up importing unique module names.
I tried to do pytest --collect-only recently and the following workaround worked for me:
To webdriver/tests/__init__.py
I have added:
import os
from tools.wpt.utils import load_source
here = os.path.dirname(__file__)
localpaths = load_source("localpaths", os.path.abspath(os.path.join(here, os.pardir, os.pardir, "tools", "localpaths.py"))) # type: ignore
and that made the following command work for me:
python3 -m pytest --rootdir=. -c tools/pytest.ini --collect-only -q webdriver/tests/bidi/**/*.py
Normally localpaths are imported in another place that pytest does not know about. This is the output I got https://gist.github.com/OrKoN/e000e32f132db86c102cc35f12fd5852
and that made the following command work for me:
python3 -m pytest --rootdir=. -c tools/pytest.ini --collect-only -q webdriver/tests/bidi/**/*.py
Note pytest
has significantly different behaviour when arguments (specifying files) are passed, which changes, among other things, how it finds the initial conftest.py
.
This is a significance difference to my command in the original issue.
With:
You ultimately get a failure:
This is because:
Per the docs:
If we instead use the
importlib
import mechanism, we get:I'm confused as to how it's resolved
..
to bewebdriver.tests.bidi
there (rather thanwebdriver.tests.bidi.browsers
).