From a4daac7eb03f934752929297fe9d9329a4e86850 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 10 Apr 2018 20:30:10 +0300 Subject: [PATCH] #3290 Fix doc --- doc/en/monkeypatch.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/en/monkeypatch.rst b/doc/en/monkeypatch.rst index a2327d4fa..221a8efe3 100644 --- a/doc/en/monkeypatch.rst +++ b/doc/en/monkeypatch.rst @@ -61,6 +61,17 @@ so that any attempts within tests to create http requests will fail. ``compile``, etc., because it might break pytest's internals. If that's unavoidable, passing ``--tb=native``, ``--assert=plain`` and ``--capture=no`` might help although there's no guarantee. + + To avoid damage of pytest from patching python stdlib functions use ``with`` + construction:: + + # content of test_module.py + + import functools + def test_partial(monkeypatch): + with monkeypatch.context() as m: + m.setattr(functools, "partial", 3) + assert functools.partial == 3 .. currentmodule:: _pytest.monkeypatch