Open segevfiner opened 6 years ago
Thanks @segevfiner for the report!
Would a fix similar to #2458 work? Or is that likely to screw up the marker/fixture discovery?
we should probably deprecate/disallow required=True and/or handle initial cli parsing differently
@cryvate I haven't tried/checked
Deprecating this will still require an alternative that we should recommend instead (Code likely uses this, so it likely requires a proper deprecation period).
Implementing this by our self requires access to the dict of arguments that were parsed that is internal to argparse. (To the best of my memory of
not what argparse does, you can pass the default value as an argument and
it still satifies required
.
If you can't use required
. You might, as a test developer, try to check
for a non default value from pytest_configure
, but that too breaks
--help
and friends, since they run pytest_configure
before doing their
thing. So figuring out the best hook for doing something like this isn't
immediatly obvious either.
It isn't that uncommon to have tests that require arguments to run. Mostly for integration style tests that might require servers and credentials and such to work.
That's what I remember of this, at least.
בתאריך 19 בדצמ' 2017 18:08, "Ronny Pfannschmidt" notifications@github.com כתב:
we should probably deprecate/disallow required=True and/or handle initial cli parsing differently
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pytest-dev/pytest/issues/3042#issuecomment-352804709, or mute the thread https://github.com/notifications/unsubscribe-auth/AXlg_5lxmTYjeihLuJLax2Y4XmeVoqv0ks5tB99wgaJpZM4REWBo .
Yes, deprecating required=True is not good.
I've worked on making --version
/ --help
work if there are any ArgumentErrors (e.g. a invalid choice) in https://github.com/pytest-dev/pytest/pull/4651.
The problem here is that pytest_cmdline_parse
is used to build the config, and then pytest_cmdline_main
handles them, but usage errors abort before this hook is called already.
In f3babf13 I reworked the code for argument validation from addopts already a bit, and thought about continuing in case of ArgumentErrors for #4651 (marking the config as having a usage error, and then quitting before the main test run, but allowing to e.g. handle --markers
), but then stopped there for now.
Similar to https://github.com/pytest-dev/pytest/issues/1999
When you add a
required
option inpytest_addoption
the--fixtures
and--markers
arguments cannot be used without specifying the required options. This was fixed for--help
in https://github.com/pytest-dev/pytest/pull/2458.Example
conftest.py
Output
Versions
Windows 10.0.16299.125 x64