support --last-failed AND other tests collected together
See original GitHub issueFrom what I gather this is not currently supported, infact it seems to just deselect all of the tests?
import pytest
@pytest.mark.only
def test_one():
pass
def test_two():
raise Exception('no')
pytest
creates:
│ .gitignore
│ CACHEDIR.TAG
│ README.md
│
└───v
└───cache
lastfailed
nodeids
stepwise
sy@sy-PC MINGW64 ~/PycharmProjects/untitled2/.pytest_cache/v/cache
$ cat lastfailed
{
"test_it.py::test_two": true
}
ideally i would like to run --last-failed and also specify some sort of marker / keyword expr, to collect other tests in with the failure(s) like so:
pytest --last-failed -m only
what this actually does is deselect both tests
========================================================================================================= test session starts =========================================================================================================
platform win32 -- Python 3.7.3, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\sy\PycharmProjects\untitled2
plugins: cov-2.8.1, forked-1.1.3, infrastructure-0.0.1, xdist-1.31.0
collected 2 items / 2 deselected
run-last-failure: rerun previous 1 failure
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
How to re-run failed tests and maintain state between test runs
Usage¶. The plugin provides two command line options to rerun failures from the last pytest invocation: --lf , --last-failed - to only re-run...
Read more >python - pytest: How to get a list of all failed tests at the end of ...
Run pytest with -rf to get it to print a list of failed tests at the end. From py.test --help : -r chars...
Read more >Run New and Failing Tests on File Change with Pytest
See how to pair Pytest and pytest-watch to run failing unit tests and new tests automatically on file changes without running the whole...
Read more >pytest Documentation - Read the Docs
Check out additional pytest resources to help you customize tests for ... by its test collection process, so asserts in supporting modules ...
Read more >pytest usage - manpages.ubuntu!
Pytest supports several ways to run and select tests from the command-line. ... Run tests by node ids Each collected test is assigned...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The word “and” has a confusing double meaning in English and in programming 😄
Currently, pytest filters, such as
--last-failed
,-m
and-k
, are ANDed together in the logic sense. That is they apply on top of each other. Or in words, “collect test if matcheslast-failed
AND matches-m
AND matches-k
”.I think @symonk is requesting to be able to OR them instead of AND. In words, “collect test if matches
last-failed
OR matches-m
”. pytest currently doesn’t support this.Some other command line programs have schemes to handle similar situations, in particular the
find
UNIX command comes to mind. For example,find -name myfile -or -empty
matches files whose name is “myfile” OR files which are empty. If the-or
is omitted the default is AND.Interestingly, pytest does allow such expressions inside
-m
and-k
, for example-m "(foo and bar) or baz"
. So one avenue to add this ability to pytest might be to combine-m
and-k
as well as--last-failed
and command line paths and all other such into one unified “filter expression” which supportsand
/or
/not
/parenthesis syntax. But that’s just an idea that would require some design work 😃Wouldn’t that invalidate the scenarios where using
--last-failed -m only
is supposed to run only the tests that (failed + haveonly
mark)? Ie, tests that have that mark but didn’t fail, should not run.IMO, the scenario “as a test writer i do not want last failed to deselect tests with a special marker even if the passed before” should not be possible with one command line and rather use 2 different command lines:
Potentially combine the results later.