-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetopic: reportingrelated to terminal output and user-facing messages and errorsrelated to terminal output and user-facing messages and errors
Description
Hi,
- If the user specifies a path to collect on the CLI which doesn't exist, the error message is good.
- If the user specifies a path to collect on the CLI which doesn't exist AND they provide an argument that was added via a
conftest.py
, the resulting error message is confusing and misdirecting.
Example layout:
tests/
tests/conftest.py
tests/test_cool_thing.py
# contents of conftest.py
def pytest_addoption(parser) -> None:
parser.addoption("--potato", default="")
Happy path example, with useful output
pytest tests/file_does_not_exist.py
ERROR: file or directory not found: tests/file_does_not_exist.py
However, adding the correct CLI arg leads to a confusing error message. The error message complains about an unrecognized argument, even though the argument is correct, and the root cause is that the specified path doesn't exist. Presumably with the missing path, conftest.py
doesn't get loaded, and the --
argument is evaluated before the collection path.
pytest tests/file_does_not_exist.py --potato=yum
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --potato=yum
Tested on
- ubuntu 20.04, python3.11
- pytest-7.4.2, pytest-8.4.1
Wasted a few hours with other engineers today on this :)
Thanks
Metadata
Metadata
Assignees
Labels
topic: configrelated to config handling, argument parsing and config filerelated to config handling, argument parsing and config filetopic: reportingrelated to terminal output and user-facing messages and errorsrelated to terminal output and user-facing messages and errors