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.11.1.tar.gz (31.3 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.11.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest-mock-3.11.1.tar.gz
Algorithm Hash digest
SHA256 7f6b125602ac6d743e523ae0bfa71e1a697a2f5534064528c6ff84c2f7c2fc7f
MD5 ec42c50bb54061bc170384b59e7fa909
BLAKE2b-256 d82db3a811ec4fa24190a9ec5013e23c89421a7916167c6240c31fdc445f850c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytest_mock-3.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 21c279fff83d70763b05f8874cc9cfb3fcacd6d354247a976f9529d19f9acf39
MD5 80b71228e2f9b639b668c4ef0fce99a7
BLAKE2b-256 da8580ae98e019a429445bfb74e153d4cb47c3695e3e908515e95e95c18237e5

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