docstr: Test workflow where user fixes errors gradually file by file using --lf.
docstr_tok: ["Test","workflow","where","user","fixes","errors","gradually","file","by","file","using","--","lf","."]
code: def test_cache_cumulative(self, pytester: Pytester) -> None:
      """Test workflow where user fixes errors gradually file by file using --lf."""
      # 1. initial run
      test_bar = pytester.makepyfile(
          test_bar="""
              def test_bar_1(): pass
              def test_bar_2(): assert 0
          """
      )
      test_foo = pytester.makepyfile(
          test_foo="""
              def test_foo_3(): pass
              def test_foo_4(): assert 0
          """
      )
      pytester.runpytest()
      assert self.get_cached_last_failed(pytester) == [
          "test_bar.py::test_bar_2",
          "test_foo.py::test_foo_4",
      ]
  
      # 2. fix test_bar_2, run only test_bar.py
      pytester.makepyfile(
          test_bar="""
              def test_bar_1(): pass
              def test_bar_2(): pass
          """
      )
      result = pytester.runpytest(test_bar)
      result.stdout.fnmatch_lines(["*2 passed*"])
      # ensure cache does not forget that test_foo_4 failed once before
      assert self.get_cached_last_failed(pytester) == [
          "test_foo.py::test_foo_4"
      ]
  
      result = pytester.runpytest("--last-failed")
      result.stdout.fnmatch_lines(
          [
              "collected 1 item",
              "run-last-failure: rerun previous 1 failure (skipped 1 file)",
              "*= 1 failed in *",
          ]
      )
      assert self.get_cached_last_failed(pytester) == [
          "test_foo.py::test_foo_4"
      ]
  
      # 3. fix test_foo_4, run only test_foo.py
      test_foo = pytester.makepyfile(
          test_foo="""
              def test_foo_3(): pass
              def test_foo_4(): pass
          """
      )
      result = pytester.runpytest(test_foo, "--last-failed")
      result.stdout.fnmatch_lines(
          [
              "collected 2 items / 1 deselected / 1 selected",
              "run-last-failure: rerun previous 1 failure",
              "*= 1 passed, 1 deselected in *",
          ]
      )
      assert self.get_cached_last_failed(pytester) == []
  
      result = pytester.runpytest("--last-failed")
      result.stdout.fnmatch_lines(["*4 passed*"])
      assert self.get_cached_last_failed(pytester) == []
  
imports: import os
  import shutil
  from pathlib import Path
  from typing import Generator
  from typing import List
  import pytest
  from _pytest.config import ExitCode
  from _pytest.monkeypatch import MonkeyPatch
  from _pytest.pytester import Pytester
  from _pytest.tmpdir import TempPathFactory
label_desc: Use image node_id 18 for calling the TestLastFailed obj's underlying member method code with example usage: obj.test_cache_cumulative(pytester) without return types