-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest.ini pythonpath doesn't work with local early-loaded (-p) plugin #11118
Comments
Rereading the docs, it says: |
You are right @a3f, currently I think that if Agreed about mentioning this gotcha in the docs.
Can you describe a bit more what the plugin does? Maybe we can suggest a different way to achieve it. |
Thanks for the confirmation. I wanted to support following command line syntax:
Or alternatively:
These extra-options and arguments would be passed as-is to Qemu, which the pytest tests are running against. My idea was to have an early plugin hook command line parsing to facilitate this. |
The import argparse
import pytest
def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption("--qemu", nargs=argparse.REMAINDER)
# Use the option
def pytest_configure(config: pytest.Config) -> None:
qemu_opts = config.getoption("qemu") or [] |
@bluetech Nice, Thanks a lot! This works fine for me. :) |
This allows plugins loaded via '-p' to benefit from the new PYTHONPATH, making the option useful in more cases and less surprising. For this to work it was required for the functionality to be part of Config rather than a separate plugin, which is unfortunate but in the end considered a small price to pay. Fix #11118. --------- Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
I am using pytest 7.2.1 on NixOS 23.05 and want to early-load a plugin, so I can do some custom command line parsing using
pytest_load_initial_conftests
. Here's my setup:Normal non-early loading of plugin works:
Early-loading plugin with manual
PYTHONPATH
override also works:But relying on
pytest.ini
pythonpath
for early-loading fails:I haven't seen anything in the docs to indicate that pythonpath is not applicable to
-p
. If that's intended behavior, it would be nice to amend the docs to reflect that. Also, I am curious if there's another way to getpytest -p my_plugin
to just work? I'd like to add-p my_plugin
to mypytest.ini
eventually, so users just need to type inpytest
and not have to worry about paths.The text was updated successfully, but these errors were encountered: