From b8e2f42ec1fc552ce145182ab5868cbfa357d0ec Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Fri, 15 Jul 2022 19:24:16 +0000 Subject: [PATCH] Add monkeypatch.context() to how-to doc intro --- doc/en/how-to/monkeypatch.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/en/how-to/monkeypatch.rst b/doc/en/how-to/monkeypatch.rst index 0ae878240..9214de77e 100644 --- a/doc/en/how-to/monkeypatch.rst +++ b/doc/en/how-to/monkeypatch.rst @@ -25,6 +25,7 @@ functionality in tests: monkeypatch.delenv(name, raising=True) monkeypatch.syspath_prepend(path) monkeypatch.chdir(path) + monkeypatch.context() All modifications will be undone after the requesting test function or fixture has finished. The ``raising`` @@ -55,6 +56,9 @@ during a test. 5. Use :py:meth:`monkeypatch.syspath_prepend ` to modify ``sys.path`` which will also call ``pkg_resources.fixup_namespace_packages`` and :py:func:`importlib.invalidate_caches`. +6. Use :py:meth:`monkeypatch.context ` to apply patches only in a specific scope, which can help +control teardown of complex fixtures or patches to the stdlib. + See the `monkeypatch blog post`_ for some introduction material and a discussion of its motivation.