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.14.0.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-mock-3.14.0.tar.gz
  • Upload date:
  • Size: 32.8 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.14.0.tar.gz
Algorithm Hash digest
SHA256 2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0
MD5 c22f3c24300091f503258d1ba5159551
BLAKE2b-256 c690a955c3ab35ccd41ad4de556596fa86685bf4fc5ffcc62d22d856cfd4e29a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_mock-3.14.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.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f
MD5 d61798dcd70655d6e2b70937e39d34ad
BLAKE2b-256 f23bb26f90f74e2986a82df6e7ac7e319b8ea7ccece1caec9f8ab6104dc70603

See more details on using hashes here.

Supported by

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