Pytest-mock

Latest version: v3.14.0

Safety actively analyzes 628903 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 11

3.6.0

------------------

* pytest-mock no longer supports Python 3.5.

* Correct type annotations for ``mocker.patch.object`` to also include the string form.
Thanks `plannigan`_ for the PR (`235`_).

* ``reset_all`` now supports ``return_value`` and ``side_effect`` keyword arguments. Thanks `alex-marty`_ for the PR (`214`_).

.. _alex-marty: https://github.com/alex-marty
.. _plannigan: https://github.com/plannigan
.. _214: https://github.com/pytest-dev/pytest-mock/pull/214
.. _235: https://github.com/pytest-dev/pytest-mock/pull/235

3.5.1

------------------

* Use ``inspect.getattr_static`` instead of resorting to ``object.__getattribute__``
magic. This should better comply with objects which implement a custom descriptor
protocol. Thanks `yesthesoup`_ for the PR (`224`_).

.. _yesthesoup: https://github.com/yesthesoup
.. _224: https://github.com/pytest-dev/pytest-mock/pull/224

3.5.0

------------------

* Now all patch functions will emit a warning instead of raising a ``ValueError`` when used
as a context-manager. Thanks `iforapsy`_ for the PR (`221`_).

* Additionally, ``mocker.patch.context_manager`` is available when the user intends to mock
a context manager (for example ``threading.Lock`` object), which will not emit that
warning.

.. _iforapsy: https://github.com/iforapsy
.. _221: https://github.com/pytest-dev/pytest-mock/pull/221

3.4.0

------------------

* Add `mock.seal` alias to the `mocker` fixture (`211`_). Thanks `coiax`_ for the PR.

* Fixed spying on exceptions not covered by the ``Exception``
superclass (`215`_), like ``KeyboardInterrupt`` -- PR `216`_
by `webknjaz`_.

Before the fix, both ``spy_return`` and ``spy_exception``
were always assigned to ``None``
whenever such an exception happened. And after this fix,
``spy_exception`` is set to a correct value of an exception
that has actually happened.

.. _coiax: https://github.com/coiax
.. _webknjaz: https://github.com/sponsors/webknjaz
.. _211: https://github.com/pytest-dev/pytest-mock/pull/211
.. _215: https://github.com/pytest-dev/pytest-mock/issues/215
.. _216: https://github.com/pytest-dev/pytest-mock/pull/216

3.3.1

------------------

* Introduce ``MockFixture`` as an alias to ``MockerFixture``.

Before ``3.3.0``, the fixture class was named ``MockFixture``, but was renamed to ``MockerFixture`` to better
match the ``mocker`` fixture. While not officially part of the API, it was later discovered that this broke
the code of some users which already imported ``pytest_mock.MockFixture`` for type annotations, so we
decided to reintroduce the name as an alias.

Note however that this is just a stop gap measure, and new code should use ``MockerFixture`` for type annotations.

* Improved typing for ``MockerFixture.patch`` (`201`_). Thanks `srittau`_ for the PR.

.. _srittau: https://github.com/srittau
.. _201: https://github.com/pytest-dev/pytest-mock/pull/201

3.3.0

------------------

* ``pytest-mock`` now includes inline type annotations and exposes them to user programs. The ``mocker`` fixture returns ``pytest_mock.MockerFixture``, which can be used to annotate your tests:

.. code-block:: python

from pytest_mock import MockerFixture

def test_foo(mocker: MockerFixture) -> None:
...

The type annotations were developed against mypy version ``0.782``, the
minimum version supported at the moment. If you run into an error that you believe to be incorrect, please open an issue.

Many thanks to `staticdev`_ for providing the initial patch (`199`_).

.. _staticdev: https://github.com/staticdev
.. _199: https://github.com/pytest-dev/pytest-mock/pull/199

Page 3 of 11

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.