MCPcopy
hub / github.com/pytest-dev/pytest / test_lastfailed_usecase

Method test_lastfailed_usecase

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

Source from the content-addressed store, hash-verified

283
284class TestLastFailed:
285 def test_lastfailed_usecase(
286 self, pytester: Pytester, monkeypatch: MonkeyPatch
287 ) -> None:
288 monkeypatch.setattr("sys.dont_write_bytecode", True)
289 p = pytester.makepyfile(
290 """
291 def test_1(): assert 0
292 def test_2(): assert 0
293 def test_3(): assert 1
294 """
295 )
296 result = pytester.runpytest(str(p))
297 result.stdout.fnmatch_lines(["*2 failed*"])
298 p = pytester.makepyfile(
299 """
300 def test_1(): assert 1
301 def test_2(): assert 1
302 def test_3(): assert 0
303 """
304 )
305 result = pytester.runpytest(str(p), "--lf")
306 result.stdout.fnmatch_lines(
307 [
308 "collected 3 items / 1 deselected / 2 selected",
309 "run-last-failure: rerun previous 2 failures",
310 "*= 2 passed, 1 deselected in *",
311 ]
312 )
313 result = pytester.runpytest(str(p), "--lf")
314 result.stdout.fnmatch_lines(
315 [
316 "collected 3 items",
317 "run-last-failure: no previously failed tests, not deselecting items.",
318 "*1 failed*2 passed*",
319 ]
320 )
321 pytester.path.joinpath(".pytest_cache", ".git").mkdir(parents=True)
322 result = pytester.runpytest(str(p), "--lf", "--cache-clear")
323 result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
324 assert pytester.path.joinpath(".pytest_cache", "README.md").is_file()
325 assert pytester.path.joinpath(".pytest_cache", ".git").is_dir()
326
327 # Run this again to make sure clear-cache is robust
328 if os.path.isdir(".pytest_cache"):
329 shutil.rmtree(".pytest_cache")
330 result = pytester.runpytest("--lf", "--cache-clear")
331 result.stdout.fnmatch_lines(["*1 failed*2 passed*"])
332
333 def test_failedfirst_order(self, pytester: Pytester) -> None:
334 pytester.makepyfile(

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected