pytest-mock/README.rst

70 lines
2.3 KiB
ReStructuredText
Raw Permalink Normal View History

2016-11-01 20:01:57 +01:00
===========
pytest-mock
===========
2021-08-31 11:33:03 +02:00
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>`_:
2016-11-01 20:01:57 +01:00
.. code-block:: python
2017-09-18 19:14:14 +02:00
import os
2019-08-24 18:33:04 +02:00
2017-09-18 19:14:14 +02:00
class UnixFS:
2019-08-24 18:33:04 +02:00
2017-09-18 19:14:14 +02:00
@staticmethod
def rm(filename):
os.remove(filename)
2019-08-24 18:33:04 +02:00
2016-11-01 20:01:57 +01:00
def test_unix_fs(mocker):
mocker.patch('os.remove')
UnixFS.rm('file')
os.remove.assert_called_once_with('file')
2021-08-31 11:33:03 +02:00
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.
2016-11-01 20:01:57 +01:00
2022-07-15 08:47:42 +02:00
|python| |version| |anaconda| |docs| |ci| |coverage| |black| |pre-commit|
2016-11-01 20:01:57 +01:00
2017-09-18 19:14:14 +02:00
.. |version| image:: http://img.shields.io/pypi/v/pytest-mock.svg
2016-11-01 20:01:57 +01:00
:target: https://pypi.python.org/pypi/pytest-mock
2019-08-24 18:33:04 +02:00
.. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest-mock.svg
2017-09-18 19:14:14 +02:00
:target: https://anaconda.org/conda-forge/pytest-mock
2016-11-01 20:01:57 +01:00
2022-07-15 08:47:42 +02:00
.. |ci| image:: https://github.com/pytest-dev/pytest-mock/workflows/test/badge.svg
2021-08-31 11:33:03 +02:00
:target: https://github.com/pytest-dev/pytest-mock/actions
2016-11-01 20:01:57 +01:00
2021-08-31 11:33:03 +02:00
.. |coverage| image:: https://coveralls.io/repos/github/pytest-dev/pytest-mock/badge.svg?branch=master
:target: https://coveralls.io/github/pytest-dev/pytest-mock?branch=master
2016-11-01 20:01:57 +01:00
.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-mock.svg
:target: https://pypi.python.org/pypi/pytest-mock/
2018-03-05 23:30:36 +01:00
2019-08-24 18:33:04 +02:00
.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black
2021-08-31 11:33:03 +02:00
.. |pre-commit| image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest-mock/master.svg
:target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest-mock/master
2022-07-15 08:47:42 +02:00
.. |docs| image:: https://readthedocs.org/projects/pytest-mock/badge/?version=latest
:target: https://pytest-mock.readthedocs.io/en/latest/?badge=latest
2016-11-01 20:01:57 +01:00
2022-07-15 08:47:42 +02:00
`Professionally supported pytest-mock is available <https://tidelift.com/subscription/pkg/pypi-pytest_mock?utm_source=pypi-pytest-mock&utm_medium=referral&utm_campaign=readme>`_.
2016-11-01 20:01:57 +01:00
2017-09-18 19:14:14 +02:00
2022-07-15 08:47:42 +02:00
Documentation
=============
2017-09-18 19:14:14 +02:00
2022-07-15 08:47:42 +02:00
For full documentation, please see https://pytest-mock.readthedocs.io/en/latest.
2019-08-24 18:33:04 +02:00
2016-11-01 20:01:57 +01:00
License
=======
Distributed under the terms of the `MIT`_ license.
2021-08-31 11:33:03 +02:00
2016-11-01 20:01:57 +01:00
.. _MIT: https://github.com/pytest-dev/pytest-mock/blob/master/LICENSE