#3290 Fix comments

This commit is contained in:
feuillemorte
2018-04-13 16:00:07 +03:00
parent a4daac7eb0
commit ba7cad3962
5 changed files with 33 additions and 15 deletions

View File

@@ -110,6 +110,21 @@ class MonkeyPatch(object):
@contextmanager
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