Skip to main content

Thin-wrapper around the mock package for easier use with pytest

Project description

This plugin provides a mocker fixture which is a thin-wrapper around the patching API provided by the mock package:

import os

class UnixFS:

    @staticmethod
    def rm(filename):
        os.remove(filename)

def test_unix_fs(mocker):
    mocker.patch('os.remove')
    UnixFS.rm('file')
    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 docs ci coverage black pre-commit

Professionally supported pytest-mock is available.

Documentation

For full documentation, please see https://pytest-mock.readthedocs.io/en/latest.

License

Distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-mock-3.13.0.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_mock-3.13.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest-mock-3.13.0.tar.gz.

File metadata

  • Download URL: pytest-mock-3.13.0.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.8

File hashes

Hashes for pytest-mock-3.13.0.tar.gz
Algorithm Hash digest
SHA256 58c73e7eae1fc05aebe7bd4b3b59eb5beb5c0b644c7e2dd3cc652a749f0056e3
MD5 8ad932a0f61791d8989c627c2cbbd296
BLAKE2b-256 dfd1b2fe0bae24b3ecb864a3370fd87141784f93978f3e6f9c746f6a2c4d3285

See more details on using hashes here.

File details

Details for the file pytest_mock-3.13.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_mock-3.13.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.8

File hashes

Hashes for pytest_mock-3.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 158462fe2124763df267f20c81f098bdccf8928e2649e5e1093955ad1e515f80
MD5 08507c59c03a86c634fa62dbe9148ca1
BLAKE2b-256 b863c4817039de0b3a9498d5da7dd8686c58f4b0e81e15f2752784e0267479d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page