pytest_addoption is called after CLI argparsing when conftest is in a subdirectory of tests
and the path is not specified
#9337
Labels
topic: config
related to config handling, argument parsing and config file
topic: reporting
related to terminal output and user-facing messages and errors
type: question
general question, might be closed after 2 weeks of inactivity
I have hit a rather confusing edge case when using
pytest_addoption
in aconftest.py
that resides in a sub-directory of thetests
directory. It appears that pytest is then performing the CLI parsing before collecting the tests and theconftest.py
(which leads to really weird issues). On the other hand, when I specify the test path manually, then pytest will do "the right thing" (= perform the CLI parsing after readin in conftest from the directory).This can be reproduced as follows:
Now, I would intuitively expect that I could now run
poetry run pytest --foobar
but this does not work:However, if I explicitly set the path where to look for tests, then it works:
Please also note that pytest is still executing conftest.py if I don't specify a CLI flag. One can for example modify
pytest_addoption(parser)
as follows:And executing
poetry run pytest
leads to the expected error:The text was updated successfully, but these errors were encountered: