README.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ===========
  2. pytest-mock
  3. ===========
  4. This plugin provides a ``mocker`` fixture which is a thin-wrapper around the patching API
  5. provided by the `mock package <http://pypi.python.org/pypi/mock>`_:
  6. .. code-block:: python
  7. import os
  8. class UnixFS:
  9. @staticmethod
  10. def rm(filename):
  11. os.remove(filename)
  12. def test_unix_fs(mocker):
  13. mocker.patch('os.remove')
  14. UnixFS.rm('file')
  15. os.remove.assert_called_once_with('file')
  16. Besides undoing the mocking automatically after the end of the test, it also provides other
  17. nice utilities such as ``spy`` and ``stub``, and uses pytest introspection when
  18. comparing calls.
  19. |python| |version| |anaconda| |docs| |ci| |coverage| |black| |pre-commit|
  20. .. |version| image:: http://img.shields.io/pypi/v/pytest-mock.svg
  21. :target: https://pypi.python.org/pypi/pytest-mock
  22. .. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest-mock.svg
  23. :target: https://anaconda.org/conda-forge/pytest-mock
  24. .. |ci| image:: https://github.com/pytest-dev/pytest-mock/workflows/test/badge.svg
  25. :target: https://github.com/pytest-dev/pytest-mock/actions
  26. .. |coverage| image:: https://coveralls.io/repos/github/pytest-dev/pytest-mock/badge.svg?branch=master
  27. :target: https://coveralls.io/github/pytest-dev/pytest-mock?branch=master
  28. .. |python| image:: https://img.shields.io/pypi/pyversions/pytest-mock.svg
  29. :target: https://pypi.python.org/pypi/pytest-mock/
  30. .. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
  31. :target: https://github.com/ambv/black
  32. .. |pre-commit| image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest-mock/master.svg
  33. :target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest-mock/master
  34. .. |docs| image:: https://readthedocs.org/projects/pytest-mock/badge/?version=latest
  35. :target: https://pytest-mock.readthedocs.io/en/latest/?badge=latest
  36. `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>`_.
  37. Documentation
  38. =============
  39. For full documentation, please see https://pytest-mock.readthedocs.io/en/latest.
  40. License
  41. =======
  42. Distributed under the terms of the `MIT`_ license.
  43. .. _MIT: https://github.com/pytest-dev/pytest-mock/blob/master/LICENSE