code: def test_resource_warning(
      pytester: Pytester, monkeypatch: pytest.MonkeyPatch
  ) -> None:
      # Some platforms (notably PyPy) don't have tracemalloc.
      # We choose to explicitly not skip this in case tracemalloc is not
      # available, using `importorskip("tracemalloc")` for example,
      # because we want to ensure the same code path does not break in those platforms.
      try:
          import tracemalloc  # noqa
  
          has_tracemalloc = True
      except ImportError:
          has_tracemalloc = False
  
      # Explicitly disable PYTHONTRACEMALLOC in case pytest's test suite is running
      # with it enabled.
      monkeypatch.delenv("PYTHONTRACEMALLOC", raising=False)
  
      pytester.makepyfile(
          """
          def open_file(p):
              f = p.open("r", encoding="utf-8")
              assert p.read_text() == "hello"
  
          def test_resource_warning(tmp_path):
              p = tmp_path.joinpath("foo.txt")
              p.write_text("hello", encoding="utf-8")
              open_file(p)
          """
      )
      result = pytester.run(sys.executable, "-Xdev", "-m", "pytest")
      expected_extra = (
          [
              "*ResourceWarning* unclosed file*",
              "*Enable tracemalloc to get traceback where the object was allocated*",
              "*See https* for more info.",
          ]
          if has_tracemalloc
          else []
      )
      result.stdout.fnmatch_lines([*expected_extra, "*1 passed*"])
  
      monkeypatch.setenv("PYTHONTRACEMALLOC", "20")
  
      result = pytester.run(sys.executable, "-Xdev", "-m", "pytest")
      expected_extra = (
          [
              "*ResourceWarning* unclosed file*",
              "*Object allocated at*",
          ]
          if has_tracemalloc
          else []
      )
      result.stdout.fnmatch_lines([*expected_extra, "*1 passed*"])
  
imports: import os
  import sys
  import warnings
  from typing import List
  from typing import Optional
  from typing import Tuple
  import pytest
  from _pytest.fixtures import FixtureRequest
  from _pytest.pytester import Pytester
label_desc: Use image node_id 23 for calling a global function with example usage: test_resource_warning(pytester, monkeypatch) without return types