From 420afe957cfcd945d418de9f0621dfd37b349d06 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 13 Sep 2023 18:39:54 -0300 Subject: [PATCH] Move remarks about context-manager to the Usage page Fix #382 --- docs/remarks.rst | 20 -------------------- docs/usage.rst | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/remarks.rst b/docs/remarks.rst index 5e20038..ef4ea68 100644 --- a/docs/remarks.rst +++ b/docs/remarks.rst @@ -100,23 +100,3 @@ to improve the flow of the test: # ... But this is arguably a little more complex than using ``pytest-mock``. - -Usage as context manager ------------------------- - -Although mocker's API is intentionally the same as ``mock.patch``'s, its use -as context manager and function decorator is **not** supported through the -fixture: - -.. code-block:: python - - def test_context_manager(mocker): - a = A() - with mocker.patch.object(a, 'doIt', return_value=True, autospec=True): # DO NOT DO THIS - assert a.doIt() == True - -The purpose of this plugin is to make the use of context managers and -function decorators for mocking unnecessary, so it will emit a warning when used as such. - -If you really intend to mock a context manager, ``mocker.patch.context_manager`` exists -which won't issue the above warning. diff --git a/docs/usage.rst b/docs/usage.rst index 4c313b0..6519f3a 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -136,3 +136,24 @@ It may receive an optional name that is shown in its ``repr``, useful for debugg .. seealso:: ``async_stub`` method, which actually the same as ``stub`` but makes async stub. + + +Usage as context manager +------------------------ + +Although mocker's API is intentionally the same as ``mock.patch``'s, its use +as context manager and function decorator is **not** supported through the +fixture: + +.. code-block:: python + + def test_context_manager(mocker): + a = A() + with mocker.patch.object(a, 'doIt', return_value=True, autospec=True): # DO NOT DO THIS + assert a.doIt() == True + +The purpose of this plugin is to make the use of context managers and +function decorators for mocking unnecessary, so it will emit a warning when used as such. + +If you really intend to mock a context manager, ``mocker.patch.context_manager`` exists +which won't issue the above warning.