Options: how to bail if not set? #12723
Replies: 2 comments 1 reply
-
I just figured out that pytest uses argparse, which supports Sorry for the noise. |
Beta Was this translation helpful? Give feedback.
1 reply
-
the recommended way currently us to use a pytest_configure hook and raising a usage-error |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scenario
request.config.getoption
parser.addoption
default
Instead, the option defaults to
None
.Question
How do I work around this natively? Is there a sentinel I can use, like
getoption
does withNotset
?FWIW: I suppose I could check if any option was specified in a
pytest_configure
hook, but that's tedious for many projects.Example
Snippet from
conftest.py
CLI
(No
--test
is specified.)Expected
pytest bails with an "option has no default, but was not specified" error.
Result
The option defaults to
None
.Beta Was this translation helpful? Give feedback.
All reactions