Test workflow where user fixes errors gradually file by file using --lf.
(self, pytester: Pytester)
| 701 | return sorted(config.cache.get("cache/lastfailed", {})) |
| 702 | |
| 703 | def test_cache_cumulative(self, pytester: Pytester) -> None: |
| 704 | """Test workflow where user fixes errors gradually file by file using --lf.""" |
| 705 | # 1. initial run |
| 706 | test_bar = pytester.makepyfile( |
| 707 | test_bar=""" |
| 708 | def test_bar_1(): pass |
| 709 | def test_bar_2(): assert 0 |
| 710 | """ |
| 711 | ) |
| 712 | test_foo = pytester.makepyfile( |
| 713 | test_foo=""" |
| 714 | def test_foo_3(): pass |
| 715 | def test_foo_4(): assert 0 |
| 716 | """ |
| 717 | ) |
| 718 | pytester.runpytest() |
| 719 | assert self.get_cached_last_failed(pytester) == [ |
| 720 | "test_bar.py::test_bar_2", |
| 721 | "test_foo.py::test_foo_4", |
| 722 | ] |
| 723 | |
| 724 | # 2. fix test_bar_2, run only test_bar.py |
| 725 | pytester.makepyfile( |
| 726 | test_bar=""" |
| 727 | def test_bar_1(): pass |
| 728 | def test_bar_2(): pass |
| 729 | """ |
| 730 | ) |
| 731 | result = pytester.runpytest(test_bar) |
| 732 | result.stdout.fnmatch_lines(["*2 passed*"]) |
| 733 | # ensure cache does not forget that test_foo_4 failed once before |
| 734 | assert self.get_cached_last_failed(pytester) == ["test_foo.py::test_foo_4"] |
| 735 | |
| 736 | result = pytester.runpytest("--last-failed") |
| 737 | result.stdout.fnmatch_lines( |
| 738 | [ |
| 739 | "collected 1 item", |
| 740 | "run-last-failure: rerun previous 1 failure (skipped 1 file)", |
| 741 | "*= 1 failed in *", |
| 742 | ] |
| 743 | ) |
| 744 | assert self.get_cached_last_failed(pytester) == ["test_foo.py::test_foo_4"] |
| 745 | |
| 746 | # 3. fix test_foo_4, run only test_foo.py |
| 747 | test_foo = pytester.makepyfile( |
| 748 | test_foo=""" |
| 749 | def test_foo_3(): pass |
| 750 | def test_foo_4(): pass |
| 751 | """ |
| 752 | ) |
| 753 | result = pytester.runpytest(test_foo, "--last-failed") |
| 754 | result.stdout.fnmatch_lines( |
| 755 | [ |
| 756 | "collected 2 items / 1 deselected / 1 selected", |
| 757 | "run-last-failure: rerun previous 1 failure", |
| 758 | "*= 1 passed, 1 deselected in *", |
| 759 | ] |
| 760 | ) |
nothing calls this directly
no test coverage detected