From b6b11ba9d8f272e9aa372d2e8ba64c793ae2457d Mon Sep 17 00:00:00 2001 From: Jack Edge Date: Tue, 6 Oct 2020 15:09:37 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A6=AD=20Add=20seal=20shortcut=20to?= =?UTF-8?q?=20mocker=20fixture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the `seal` function to the mocker fixture, taken directly from the `mock` module. Since `seal` was only added in Python 3.7, it is not always present, just like AsyncMock. --- README.rst | 1 + src/pytest_mock/plugin.py | 2 ++ tests/test_pytest_mock.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/README.rst b/README.rst index 5776a47..dec2d7e 100644 --- a/README.rst +++ b/README.rst @@ -81,6 +81,7 @@ Also, as a convenience, these names from the ``mock`` module are accessible dire * `call `_ *(Version 1.1)* * `sentinel `_ *(Version 1.2)* * `mock_open `_ +* `seal `_ *(Version ???)* It is also possible to use mocking functionality from fixtures of other scopes using the appropriate mock fixture: diff --git a/src/pytest_mock/plugin.py b/src/pytest_mock/plugin.py index 6ee2ed7..c9f3853 100644 --- a/src/pytest_mock/plugin.py +++ b/src/pytest_mock/plugin.py @@ -65,6 +65,8 @@ def __init__(self, config: Any) -> None: self.create_autospec = mock_module.create_autospec self.sentinel = mock_module.sentinel self.mock_open = mock_module.mock_open + if hasattr(mock_module, "seal"): + self.seal = mock_module.seal def resetall(self) -> None: """Call reset_mock() on all patchers started by this fixture.""" diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py index 129bc88..33a80b2 100644 --- a/tests/test_pytest_mock.py +++ b/tests/test_pytest_mock.py @@ -152,6 +152,12 @@ def test_mock_patch_dict_resetall(mocker: MockerFixture) -> None: "NonCallableMock", "PropertyMock", "sentinel", + pytest.param( + "seal", + marks=pytest.mark.skipif( + sys.version_info < (3, 7), reason="seal is present on 3.7 and above" + ), + ), ], ) def test_mocker_aliases(name: str, pytestconfig: Any) -> None: From 8990da926392acd82a977a102ea8ff732e48835b Mon Sep 17 00:00:00 2001 From: Jack Edge Date: Wed, 7 Oct 2020 11:56:14 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=96=20Update=20version=20in=20READ?= =?UTF-8?q?ME.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The next release is 3.4, so updated the README.md file accordingly for when the `.seal` convenience will be available. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dec2d7e..5bf09a9 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ Also, as a convenience, these names from the ``mock`` module are accessible dire * `call `_ *(Version 1.1)* * `sentinel `_ *(Version 1.2)* * `mock_open `_ -* `seal `_ *(Version ???)* +* `seal `_ *(Version 3.4)* It is also possible to use mocking functionality from fixtures of other scopes using the appropriate mock fixture: From c20b71b9c9320abb125d32951df28eb87af79760 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 7 Oct 2020 08:35:44 -0300 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 222182e..04a08da 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,11 @@ +3.4.0 (UNRELEASED) +------------------ + +* Add `mock.seal` alias to the `mocker` fixture (`#211`_). Thanks `@coiax`_ for the PR. + +.. _@coiax: https://github.com/coiax +.. _#211: https://github.com/pytest-dev/pytest-mock/pull/211 + 3.3.1 (2020-08-24) ------------------