MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_lastfailed_usecase

Method test_lastfailed_usecase

testing/test_cacheprovider.py:265–311  ·  view source on GitHub ↗
(
        self, pytester: Pytester, monkeypatch: MonkeyPatch
    )

Source from the content-addressed store, hash-verified

263
264class TestLastFailed:
265 def test_lastfailed_usecase(
266 self, pytester: Pytester, monkeypatch: MonkeyPatch
267 ) -> None:
268 monkeypatch.setattr("sys.dont_write_bytecode", True)
269 p = pytester.makepyfile(
270 """
271 def test_1(): assert 0
272 def test_2(): assert 0
273 def test_3(): assert 1
274 """
275 )
276 result = pytester.runpytest(str(p))
277 result.stdout.fnmatch_lines(["*2 failed*"])
278 p = pytester.makepyfile(
279 """
280 def test_1(): assert 1
281 def test_2(): assert 1
282 def test_3(): assert 0
283 """
284 )
285 result = pytester.runpytest(str(p), "--lf")
286 result.stdout.fnmatch_lines(
287 [
288 "collected 3 items / 1 deselected / 2 selected",
289 "run-last-failure: rerun previous 2 failures",
290 "*= 2 passed, 1 deselected in *",
291 ]
292 )
293 result = pytester.runpytest(str(p), "--lf")
294 result.stdout.fnmatch_lines(
295 [
296 "collected 3 items",
297 "run-last-failure: no previously failed tests, not deselecting items.",
298 "*1 failed*2 passed*",
299 ]
300 )
301 pytester.path.joinpath(".pytest_cache", ".git").mkdir(parents=True)
302 result = pytester.runpytest(str(p), "--lf", "--cache-clear")
303 result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
304 assert pytester.path.joinpath(".pytest_cache", "README.md").is_file()
305 assert pytester.path.joinpath(".pytest_cache", ".git").is_dir()
306
307 # Run this again to make sure clear-cache is robust
308 if os.path.isdir(".pytest_cache"):
309 shutil.rmtree(".pytest_cache")
310 result = pytester.runpytest("--lf", "--cache-clear")
311 result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
312
313 def test_failedfirst_order(self, pytester: Pytester) -> None:
314 pytester.makepyfile(

Callers

nothing calls this directly

Calls 5

setattrMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected