Skip to content

Commit

Permalink
馃Ν Add seal shortcut to mocker fixture (#211)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
  • Loading branch information
coiax and nicoddemus committed Oct 7, 2020
1 parent bd8f613 commit 9e1464b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 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)
------------------

Expand Down
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -81,6 +81,7 @@ Also, as a convenience, these names from the ``mock`` module are accessible dire
* `call <https://docs.python.org/3/library/unittest.mock.html#call>`_ *(Version 1.1)*
* `sentinel <https://docs.python.org/3/library/unittest.mock.html#sentinel>`_ *(Version 1.2)*
* `mock_open <https://docs.python.org/3/library/unittest.mock.html#mock-open>`_
* `seal <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.seal>`_ *(Version 3.4)*

It is also possible to use mocking functionality from fixtures of other scopes using
the appropriate mock fixture:
Expand Down
2 changes: 2 additions & 0 deletions src/pytest_mock/plugin.py
Expand Up @@ -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."""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_pytest_mock.py
Expand Up @@ -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:
Expand Down

0 comments on commit 9e1464b

Please sign in to comment.