class_docstr: Object returned by the ``monkeypatch`` fixture keeping a record of setattr/item/env/syspath changes.
      
class_docstr_tok: ["Object","returned","by","the","``","monkeypatch","``","fixture","keeping","a","record","of","setattr\/item\/env\/syspath","changes","."]
docstr: Context manager that returns a new :class:`MonkeyPatch` object which
  undoes any patching done inside the ``with`` block upon exit:
  
  .. 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 `#3290 <https://github.com/pytest-dev/pytest/issues/3290>`_.
docstr_tok: ["Context","manager","that","returns","a","new",":","class",":","`","MonkeyPatch","`","object","which","undoes","any","patching","done","inside","the","``","with","``","block","upon","exit",":","..","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","`","#","3290","<","https",":","\/\/github.com\/pytest-dev\/pytest\/issues\/3290",">","`","_","."]
code: def context(self):
      """
      Context manager that returns a new :class:`MonkeyPatch` object which
      undoes any patching done inside the ``with`` block upon exit:
  
      .. 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 `#3290 <https://github.com/pytest-dev/pytest/issues/3290>`_.
      """
      m = MonkeyPatch()
      try:
          yield m
      finally:
          m.undo()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import re
  import sys
  import warnings
  from contextlib import contextmanager
  import six
  import pytest
  from _pytest.fixtures import fixture
  from _pytest.pathlib import Path
label_desc: Use image node_id 2 for calling the MonkeyPatch obj's underlying member method code with example usage: obj.context() without return types