-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 "--deselect" command line option #3201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @uSpike!
testing/test_session.py
Outdated
""") | ||
result = testdir.runpytest("--deselect=test_a.py::test_a2[1]") | ||
assert result.ret == 0 | ||
result.stdout.fnmatch_lines(["*11 passed, 1 deselected*"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be 10 passed, 1 deselected
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think it would be better to use -v
and deselect two tests and ensure they are not being run. You can parametrize test_a2
using a smaller value (say 3) so the test remains tidy and small.
_pytest/main.py
Outdated
for colitem in items: | ||
for opt in deselectopt: | ||
if colitem.nodeid.startswith(opt): | ||
deselected.append(colitem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this needs a break
after deselected.append(colitem)
_pytest/main.py
Outdated
deselected = [] | ||
for colitem in items: | ||
for opt in deselectopt: | ||
if colitem.nodeid.startswith(opt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
startswith can take a tuple which can be used as a much better selector
instead of a loop and the for else hack it could simply use colitem.nodeid.startswith(deselect_prefixes)
i presume the break was not added due to the expectation of the prefixes being distinct/non-overlapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh cool, thanks I didnt realize str.startswith()
takes a tuple. That's great.
_pytest/main.py
Outdated
@@ -66,6 +66,8 @@ def pytest_addoption(parser): | |||
help="try to interpret all arguments as python packages.") | |||
group.addoption("--ignore", action="append", metavar="path", | |||
help="ignore path during collection (multi-allowed).") | |||
group.addoption("--deselect", action="append", metavar="item", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i propose a metavar of nodeid_prefix
d36ada9
to
f7828a8
Compare
@RonnyPfannschmidt @nicoddemus I've implemented your suggestions, thanks much for the feedback. |
_pytest/main.py
Outdated
remaining = [] | ||
deselected = [] | ||
for colitem in items: | ||
if colitem.nodeid.startswith(tuple(deselect_prefixes)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done, please also move the call to tuple
to the place where deselect_prefixes
is declared
7386d9c
to
0e2522c
Compare
In #3198 you said:
This would not need a new option then. btw: I've also thought about this being something negating |
Thanks @uSpike! |
I still think that it is confusing to have
|
I guess that it makes sense to mentioned in the docs what the differences between |
I'm not sure if it's more or less confusing with |
I have a working implementation here: uSpike@8b98792 |
@uSpike |
Fixes #3198
I implemented this as a new CLI option
--deselect
since it does have different functionality than--ignore
, which completely ignores the file.The code matches any
nodeid
thatstartswith()
any--deselect
flag.changelog
folder, with a name like<ISSUE NUMBER>.<TYPE>.rst
. See changelog/README.rst for details.features
branch for new features and removals/deprecations.AUTHORS
in alphabetical order