Skip to content
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

add_option no longer works because of ambiguous option #3413

Open
teddyrendahl opened this issue Apr 19, 2018 · 10 comments

Comments

Projects
None yet
5 participants
@teddyrendahl
Copy link

commented Apr 19, 2018

Description

In pytest=3.5 many of my custom command line arguments added via parser.add_option are now unusable. When I try and use a custom argument defined like such:

def pytest_addoption(parser):
    parser.addoption("--show", action="store_true")

I get the following error:

$ py.test --show
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: ambiguous option: --show could match --showlocals, --show-capture

It looks like my custom parser option is conflicting with those found in other places. I can see the point of having my custom argument be more specific, but at the same time I am defining it explicitly as an option. It should not be ambiguous! The interesting thing is this works fine in older versions of pytest. I explicitly tested this with pytest=3.4.1.

Environment

pytest installed via Conda with conda-forge recipes

@pytestbot

This comment has been minimized.

Copy link

commented Apr 19, 2018

GitMate.io thinks possibly related issues are #1932 (pytest --pdb is no longer working with Flask_testing), #846 (--ignore option doesn't work), #554 (pytest 2.6 no longer works with mocks and fixtures), #1885 (Module-level skip no longer works), and #2635 (test logging interaction no longer works due to hypothesis usage).

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

The interesting thing is this works fine in older versions of pytest

It looks like your own option is not added anymore for some reason. Where do you add it?
I am getting the same error with pytest --show.

Relevant argparse code:
https://github.com/python/cpython/blob/20d68dfcc07bd389ce2ea7b0773c44d97ebeb68d/Lib/argparse.py#L2123 (which pytest could change).

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Apr 20, 2018

this is a python issue and actually a correct error, before python did this chec explicitly, they made everything bad and broken by default, we cant even fix it on older pythons because the stdlib is just bad on those

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

The problem here is that the check is done before conftests / pytest_addoption is triggered apparently.

Bisected to 1a650a9, which adds --show-terminal.
There is no problem when adding a --show option just after --show-terminal, i.e. argparse correctly handles --show from there even if there is --show-terminal.

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Apr 20, 2018

@blueyed yeah, but in the end this is a duplicate of #1146 and wed need #1149 for a fix ^^

argparse is broken, and when we add new arguments it may break other people that use a prefix of those

@teddyrendahl

This comment has been minimized.

Copy link
Author

commented Apr 20, 2018

@blueyed The example above is added in my conftest.py

@RonnyPfannschmidt Am I understanding correctly that this was an existing issue in older version of pytest but there are newer command line options in pytest=3.5 that I'm conflicting with?

Also realized I didn't state above, but since we are discussing argparse I'm running python=3.6.3

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

Hmm.. for me pytest --customoption fails with pytest: error: unrecognized arguments: --customoption when trying to use it from conftest. But it gets there eventually via consider_conftest later.
(I am using options via a local plugin usually)

@teddyrendahl

there are newer command line options in pytest=3.5 that I'm conflicting with?

Yes.

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

It appears that --show in a conftest works with 3.4.1 only because there is --showlocals already, which gets used/matched then!

@blueyed

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2018

Side note: patching _get_option_tuples to return an empty tuple always (in the early stage) breaks -ra, which needs to become -r a then.

@Zac-HD

This comment has been minimized.

Copy link
Member

commented Jun 25, 2019

Closed by #5469.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.