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 1 commit
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
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 ???)*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure what to put for the version string here. Semver would imply that the next version would be 3.4, but I don't know if there's a major release coming up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, the next version would be 3.4 given the new feature, please update it. 馃憤


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