Test workflow where user fixes errors gradually file by file using --lf.
(self, pytester: Pytester)
| 676 | return sorted(config.cache.get("cache/lastfailed", {})) |
| 677 | |
| 678 | def test_cache_cumulative(self, pytester: Pytester) -> None: |
| 679 | """Test workflow where user fixes errors gradually file by file using --lf.""" |
| 680 | # 1. initial run |
| 681 | test_bar = pytester.makepyfile( |
| 682 | test_bar=""" |
| 683 | def test_bar_1(): pass |
| 684 | def test_bar_2(): assert 0 |
| 685 | """ |
| 686 | ) |
| 687 | test_foo = pytester.makepyfile( |
| 688 | test_foo=""" |
| 689 | def test_foo_3(): pass |
| 690 | def test_foo_4(): assert 0 |
| 691 | """ |
| 692 | ) |
| 693 | pytester.runpytest() |
| 694 | assert self.get_cached_last_failed(pytester) == [ |
| 695 | "test_bar.py::test_bar_2", |
| 696 | "test_foo.py::test_foo_4", |
| 697 | ] |
| 698 | |
| 699 | # 2. fix test_bar_2, run only test_bar.py |
| 700 | pytester.makepyfile( |
| 701 | test_bar=""" |
| 702 | def test_bar_1(): pass |
| 703 | def test_bar_2(): pass |
| 704 | """ |
| 705 | ) |
| 706 | result = pytester.runpytest(test_bar) |
| 707 | result.stdout.fnmatch_lines(["*2 passed*"]) |
| 708 | # ensure cache does not forget that test_foo_4 failed once before |
| 709 | assert self.get_cached_last_failed(pytester) == ["test_foo.py::test_foo_4"] |
| 710 | |
| 711 | result = pytester.runpytest("--last-failed") |
| 712 | result.stdout.fnmatch_lines( |
| 713 | [ |
| 714 | "collected 1 item", |
| 715 | "run-last-failure: rerun previous 1 failure (skipped 1 file)", |
| 716 | "*= 1 failed in *", |
| 717 | ] |
| 718 | ) |
| 719 | assert self.get_cached_last_failed(pytester) == ["test_foo.py::test_foo_4"] |
| 720 | |
| 721 | # 3. fix test_foo_4, run only test_foo.py |
| 722 | test_foo = pytester.makepyfile( |
| 723 | test_foo=""" |
| 724 | def test_foo_3(): pass |
| 725 | def test_foo_4(): pass |
| 726 | """ |
| 727 | ) |
| 728 | result = pytester.runpytest(test_foo, "--last-failed") |
| 729 | result.stdout.fnmatch_lines( |
| 730 | [ |
| 731 | "collected 2 items / 1 deselected / 1 selected", |
| 732 | "run-last-failure: rerun previous 1 failure", |
| 733 | "*= 1 passed, 1 deselected in *", |
| 734 | ] |
| 735 | ) |
nothing calls this directly
no test coverage detected