class_docstr: Helper to conveniently monkeypatch attributes/items/environment
  variables/syspath.
  
  Returned by the :fixture:`monkeypatch` fixture.
  
  .. versionchanged:: 6.2
      Can now also be used directly as `pytest.MonkeyPatch()`, for when
      the fixture is not available. In this case, use
      :meth:`with MonkeyPatch.context() as mp: <context>` or remember to call
      :meth:`undo` explicitly.
docstr: Context manager that returns a new :class:`MonkeyPatch` object
  which undoes any patching done inside the ``with`` block upon exit.
  
  Example:
  
  .. code-block:: python
  
      import functools
  
  
      def test_partial(monkeypatch):
          with monkeypatch.context() as m:
              m.setattr(functools, "partial", 3)
  
  Useful in situations where it is desired to undo some patches before the test ends,
  such as mocking ``stdlib`` functions that might break pytest itself if mocked (for examples
  of this see :issue:`3290`).
code: def context(cls) -> Generator["MonkeyPatch", None, None]:
      """Context manager that returns a new :class:`MonkeyPatch` object
      which undoes any patching done inside the ``with`` block upon exit.
  
      Example:
  
      .. code-block:: python
  
          import functools
  
  
          def test_partial(monkeypatch):
              with monkeypatch.context() as m:
                  m.setattr(functools, "partial", 3)
  
      Useful in situations where it is desired to undo some patches before the test ends,
      such as mocking ``stdlib`` functions that might break pytest itself if mocked (for examples
      of this see :issue:`3290`).
      """
      m = cls()
      try:
          yield m
      finally:
          m.undo()
  
imports: import os
  import re
  import sys
  import warnings
  from contextlib import contextmanager
  from typing import Any
  from typing import final
  from typing import Generator
  from typing import List
  from typing import Mapping
  from typing import MutableMapping
  from typing import Optional
  from typing import overload
  from typing import Tuple
  from typing import TypeVar
  from typing import Union
  from _pytest.fixtures import fixture
  from _pytest.warning_types import PytestWarning
label_desc: Use image node_id 2 for calling the MonkeyPatch obj's underlying member method code with example usage: obj.context(cls) without return types