Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃Ν Add seal shortcut to mocker fixture #211

Merged
merged 3 commits into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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