From 6578726c9909250a0c93d4bfbb03a2bb35bcfed1 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 26 Aug 2019 12:13:35 -0300 Subject: [PATCH 1/5] bpo-37955: mock.patch incorrect reference to Mock mock.patch mentions that keyword arguments are passed to Mock when it passes to MagicMock by default. This PR fixes that. --- Doc/library/unittest.mock.rst | 2 +- Lib/unittest/mock.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 19e9715102bf3a..8e56190df2c39b 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1369,7 +1369,7 @@ patch "as"; very useful if :func:`patch` is creating a mock object for you. :func:`patch` takes arbitrary keyword arguments. These will be passed to - the :class:`Mock` (or *new_callable*) on construction. + the :class:`MagicMock` (or *new_callable*) on construction. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are available for alternate use-cases. diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 298b41e0d7e4dd..372aed696ac94e 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1651,7 +1651,7 @@ def patch( "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to - the `Mock` (or `new_callable`) on construction. + the `MagicMock` (or `new_callable`) on construction. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. From 7c55aaa1e996cc80945b0f4554be30e27cf0f1d9 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Sat, 30 Nov 2019 04:19:42 -0300 Subject: [PATCH 2/5] bpo-37955: includes reference to AsyncMock This patch adds information about possible use of a AsyncMock when passing arbitrary arguments to mock.patch. --- Doc/library/unittest.mock.rst | 3 ++- Lib/unittest/mock.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 8e56190df2c39b..3364e0539018de 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1369,7 +1369,8 @@ patch "as"; very useful if :func:`patch` is creating a mock object for you. :func:`patch` takes arbitrary keyword arguments. These will be passed to - the :class:`MagicMock` (or *new_callable*) on construction. + to construct a :class:`AsyncMock` if the patched object is an async function, + to :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are available for alternate use-cases. diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 372aed696ac94e..6fb38197c44ea5 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1651,7 +1651,8 @@ def patch( "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to - the `MagicMock` (or `new_callable`) on construction. + to construct a `AsyncMock` if the patched object is an async function, + to `MagicMock` otherwise or to `new_callable` if specified. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. From 39dd5a066608a034c980305d019e362e77c0dd4f Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 2 Dec 2019 05:34:41 -0300 Subject: [PATCH 3/5] bpo-37955: fix grammar and simplify wording --- Doc/library/unittest.mock.rst | 4 ++-- Lib/unittest/mock.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 3364e0539018de..49630b3a1b1fe7 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1369,8 +1369,8 @@ patch "as"; very useful if :func:`patch` is creating a mock object for you. :func:`patch` takes arbitrary keyword arguments. These will be passed to - to construct a :class:`AsyncMock` if the patched object is an async function, - to :class:`MagicMock` otherwise or to *new_callable* if specified. + :class:`AsyncMock` if the patched object is an async function, to + :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are available for alternate use-cases. diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 6fb38197c44ea5..99839709577298 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1651,8 +1651,8 @@ def patch( "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to - to construct a `AsyncMock` if the patched object is an async function, - to `MagicMock` otherwise or to `new_callable` if specified. + `AsyncMock` if the patched object is an async function, to `MagicMock` + otherwise or to `new_callable` if specified. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. From bebae7a80eb169a8ebd034920e524505aa5bd940 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 9 Dec 2019 22:38:01 -0300 Subject: [PATCH 4/5] bpo-37955: clarify relation to other async objects --- Doc/library/unittest.mock.rst | 2 +- Lib/unittest/mock.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 49630b3a1b1fe7..e03dcbc5d1370b 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1369,7 +1369,7 @@ patch "as"; very useful if :func:`patch` is creating a mock object for you. :func:`patch` takes arbitrary keyword arguments. These will be passed to - :class:`AsyncMock` if the patched object is an async function, to + :class:`AsyncMock` if the patched object is asynchronous, to :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 99839709577298..3f071e96b1f957 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1651,7 +1651,7 @@ def patch( "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to - `AsyncMock` if the patched object is an async function, to `MagicMock` + `AsyncMock` if the patched object is asynchronous, to `MagicMock` otherwise or to `new_callable` if specified. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are From 0744968cb94bd597af39f2096483acc1d66f2cb8 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 9 Dec 2019 22:53:04 -0300 Subject: [PATCH 5/5] bpo-37955: remove trailing whitespace --- Doc/library/unittest.mock.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index e03dcbc5d1370b..c19dab5a8d8927 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -1369,7 +1369,7 @@ patch "as"; very useful if :func:`patch` is creating a mock object for you. :func:`patch` takes arbitrary keyword arguments. These will be passed to - :class:`AsyncMock` if the patched object is asynchronous, to + :class:`AsyncMock` if the patched object is asynchronous, to :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy