Skip to content

Commit

Permalink
Drop deprecated 'mock' alias to 'mocker'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jan 4, 2020
1 parent fd02462 commit ccb76e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Breaking Changes
always raising the first exception instead: assigning to ``side_effect`` causes
``unittest.mock`` to behave this way (`#175`_).

* The deprecated ``mock`` alias to the ``mocker`` fixture has finally been removed.

.. _#175: https://github.com/pytest-dev/pytest-mock/issues/175


Expand Down
21 changes: 10 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
pytest-mock
===========

This plugin installs a ``mocker`` fixture which is a thin-wrapper around the patching API
provided by the `mock package <http://pypi.python.org/pypi/mock>`_,
but with the benefit of not having to worry about undoing patches at the end
of a test:
This plugin provides a ``mocker`` fixture which is a thin-wrapper around the patching API
provided by the `mock package <http://pypi.python.org/pypi/mock>`_:

.. code-block:: python
Expand All @@ -23,6 +21,9 @@ of a test:
os.remove.assert_called_once_with('file')
Besides undoing the mocking automatically after the end of the test, it also provides other
nice utilities such as ``spy`` and ``stub``, and uses pytest introspection when
comparing calls.

|python| |version| |anaconda| |ci| |coverage| |black|

Expand Down Expand Up @@ -70,7 +71,7 @@ The supported methods are:
* `mocker.stopall <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch.stopall>`_
* ``mocker.resetall()``: calls `reset_mock() <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.reset_mock>`_ in all mocked objects up to this point.

These objects from the ``mock`` module are accessible directly from ``mocker`` for convenience:
Also, as a convenience, these names from the ``mock`` module are accessible directly from ``mocker``:

* `Mock <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock>`_
* `MagicMock <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.MagicMock>`_
Expand All @@ -85,7 +86,7 @@ These objects from the ``mock`` module are accessible directly from ``mocker`` f
Spy
---

The spy acts exactly like the original method in all cases, except the spy
The ``mocker.spy`` object acts exactly like the original method in all cases, except the spy
also tracks method calls, return values and exceptions raised.

.. code-block:: python
Expand All @@ -111,7 +112,7 @@ In addition, spy objects contain two extra attributes:
* ``spy_exception``: contain the last exception value raised by the spied function/method when
it was last called, or ``None`` if no exception was raised.

It also works for class and static methods.
``mocker.spy`` also works for class and static methods.

.. note::

Expand All @@ -124,9 +125,8 @@ It also works for class and static methods.
Stub
----


The stub is a mock object that accepts any arguments and is useful to test callbacks, for instance.
May be passed a name to be used by the constructed stub object in its repr (useful for debugging).
The stub is a mock object that accepts any arguments and is useful to test callbacks.
It may receive an optional name that is shown in its ``repr``, useful for debugging.

.. code-block:: python
Expand All @@ -143,7 +143,6 @@ May be passed a name to be used by the constructed stub object in its repr (usef
Improved reporting of mock call assertion errors
------------------------------------------------


This plugin monkeypatches the mock library to improve pytest output for failures
of mock call assertions like ``Mock.assert_called_with()`` by hiding internal traceback
entries from the ``mock`` module.
Expand Down
13 changes: 0 additions & 13 deletions src/pytest_mock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,6 @@ def mocker(pytestconfig):
result.stopall()


@pytest.fixture
def mock(mocker):
"""
Same as "mocker", but kept only for backward compatibility.
"""
import warnings

warnings.warn(
'"mock" fixture has been deprecated, use "mocker" instead', DeprecationWarning
)
return mocker


_mock_module_patches = []
_mock_module_originals = {}

Expand Down
22 changes: 0 additions & 22 deletions tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,6 @@ def test_mock_patch_dict_resetall(mocker):
assert x == {"new": 10}


def test_deprecated_mock(testdir):
"""
Use backward-compatibility-only mock fixture to ensure complete coverage.
"""
p1 = testdir.makepyfile(
"""
import os
def test(mock, tmpdir):
mock.patch("os.listdir", return_value=["mocked"])
assert os.listdir(str(tmpdir)) == ["mocked"]
mock.stopall()
assert os.listdir(str(tmpdir)) == []
"""
)
result = testdir.runpytest(str(p1))
result.stdout.fnmatch_lines(
['*DeprecationWarning: "mock" fixture has been deprecated, use "mocker"*']
)
assert result.ret == 0


@pytest.mark.parametrize(
"name",
[
Expand Down

0 comments on commit ccb76e5

Please sign in to comment.