code: def test_lastfailed_creates_cache_when_needed(
      self, pytester: Pytester
  ) -> None:
      # Issue #1342
      pytester.makepyfile(test_empty="")
      pytester.runpytest("-q", "--lf")
      assert not os.path.exists(".pytest_cache/v/cache/lastfailed")
  
      pytester.makepyfile(
          test_successful="def test_success():\n    assert True"
      )
      pytester.runpytest("-q", "--lf")
      assert not os.path.exists(".pytest_cache/v/cache/lastfailed")
  
      pytester.makepyfile(
          test_errored="def test_error():\n    assert False"
      )
      pytester.runpytest("-q", "--lf")
      assert os.path.exists(".pytest_cache/v/cache/lastfailed")
  
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 12 for calling the TestLastFailed obj's underlying member method code with example usage: obj.test_lastfailed_creates_cache_when_needed(pytester) without return types