code: def test_gitignore(pytester: Pytester) -> None:
      """Ensure we automatically create .gitignore file in the pytest_cache directory (#3286)."""
      from _pytest.cacheprovider import Cache
  
      config = pytester.parseconfig()
      cache = Cache.for_config(config, _ispytest=True)
      cache.set("foo", "bar")
      msg = "# Created by pytest automatically.\n*\n"
      gitignore_path = cache._cachedir.joinpath(".gitignore")
      assert gitignore_path.read_text(encoding="UTF-8") == msg
  
      # Does not overwrite existing/custom one.
      gitignore_path.write_text("custom", encoding="utf-8")
      cache.set("something", "else")
      assert gitignore_path.read_text(encoding="UTF-8") == "custom"
  
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 4 for calling a global function with example usage: test_gitignore(pytester) without return types