From ccb76e55501666857106e48e86cf24d7f5e0031b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 4 Jan 2020 15:37:35 -0300 Subject: [PATCH] Drop deprecated 'mock' alias to 'mocker' --- CHANGELOG.rst | 2 ++ README.rst | 21 ++++++++++----------- src/pytest_mock/plugin.py | 13 ------------- tests/test_pytest_mock.py | 22 ---------------------- 4 files changed, 12 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6ba2d56..09b85c8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/README.rst b/README.rst index 452411a..5b5f12b 100644 --- a/README.rst +++ b/README.rst @@ -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 `_, -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 `_: .. code-block:: python @@ -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| @@ -70,7 +71,7 @@ The supported methods are: * `mocker.stopall `_ * ``mocker.resetall()``: calls `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 `_ * `MagicMock `_ @@ -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 @@ -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:: @@ -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 @@ -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. diff --git a/src/pytest_mock/plugin.py b/src/pytest_mock/plugin.py index dad8465..9e60ec6 100644 --- a/src/pytest_mock/plugin.py +++ b/src/pytest_mock/plugin.py @@ -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 = {} diff --git a/tests/test_pytest_mock.py b/tests/test_pytest_mock.py index 0ba2a2a..d1635f5 100644 --- a/tests/test_pytest_mock.py +++ b/tests/test_pytest_mock.py @@ -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", [