Add "--deselect" command line option#3201
Conversation
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.
This should be 10 passed, 1 deselected right?
There was a problem hiding this comment.
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.
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.
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.
Oh cool, thanks I didnt realize str.startswith() takes a tuple. That's great.
_pytest/main.py
Outdated
| 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.
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.
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
--deselectsince it does have different functionality than--ignore, which completely ignores the file.The code matches any
nodeidthatstartswith()any--deselectflag.changelogfolder, with a name like<ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.featuresbranch for new features and removals/deprecations.AUTHORSin alphabetical order