-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
The sun has long set, but I'm still sitting in my chair after all the hours fighting with PyTest. PyTest surely is magical, but when the magic does not work as intended, it can drive you mad like a company's "voice assistant" that does not help you, but also does not let you talk to a human. Sometimes I really long for Python's unittest way of doing what the user asks.
Our tests system is complex. Everything happens remotely. I'm not running pytest, the system does. The system runs pytest program and allows me to specify CLI args.
Here is our dir structure
third_party/
├─ databricks_cli/
│ ├─ __init__.py
│ ├─ ...
│ ├─ tests/
│ │ ├─ __init__.py
│ │ ├─ conftest.py
│ │ ├─ utils.py
│ │ ├─ group_foo/
│ │ │ ├─ __init__.py
│ │ │ ├─ test_foo.py
test_foo.py:
from tests import utils
E ModuleNotFoundError: No module named 'tests'
Also
from tests import conftest
E ModuleNotFoundError: No module named 'tests'
Also
import conftest
E ModuleNotFoundError: No module named 'conftest'
When I do the equivalent of cd "third_party/databricks_cli" && pytest, the sys.path only has third_party, not third_party/databricks_cli.
When I do the equivalent of cd "third_party/databricks_cli/tests" && pytest, the sys.path only has third_party, not third_party/databricks_cli.
unittest has --start-directory and --top-level-directory and changing them results in actual changes.
Wherever I run, there are only walls.
I know that using python -m pytest instead of pytest would solve the issue. But I cannot replace the pytest command executable.
I see people trying to use rootdir to affect sys.path. The documentation now tells in bold letters that's wrong. #4594
I was hopeful when I saw that a PR added a pythonpath option. #9134 I tried pytest --override-ini='pythonpath=foo', but this option is not really working for me and some other users: #11311 And it looks like pythonpath is not really PYTHONPATH. Back to square one.
I feel powerless. There seems to be nothing I can do to change the PyTests's sys.path behaviors.
A simple thing. Adding current directory to sys.path. Impossible.
I'm sad and tired. Thank you for listening. You can close this bug as "works as intended" now.