code: def test_preserve_modules(self, monkeypatch: MonkeyPatch) -> None:
      key = [self.key + str(i) for i in range(3)]
      assert not any(k in sys.modules for k in key)
      for i, k in enumerate(key):
          mod = ModuleType("something" + str(i))
          monkeypatch.setitem(sys.modules, k, mod)
      original = dict(sys.modules)
  
      def preserve(name):
          return name in (key[0], key[1], "some-other-key")
  
      snapshot = SysModulesSnapshot(preserve=preserve)
      sys.modules[key[0]] = original[key[0]] = ModuleType(
          "something else0"
      )
      sys.modules[key[1]] = original[key[1]] = ModuleType(
          "something else1"
      )
      sys.modules[key[2]] = ModuleType("something else2")
      snapshot.restore()
      assert sys.modules == original
  
imports: import os
  import subprocess
  import sys
  import time
  from types import ModuleType
  from typing import List
  import _pytest.pytester
  import pytest
  from _pytest.config import ExitCode
  from _pytest.config import PytestPluginManager
  from _pytest.monkeypatch import MonkeyPatch
  from _pytest.pytester import HookRecorder
  from _pytest.pytester import LineMatcher
  from _pytest.pytester import Pytester
  from _pytest.pytester import SysModulesSnapshot
  from _pytest.pytester import SysPathsSnapshot
label_desc: Use image node_id 4 for calling the TestSysModulesSnapshot obj's underlying member method code with example usage: obj.test_preserve_modules(monkeypatch) and returns: unknown