Python MIT

pytest-mock

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

P

pytest-dev

Dernière activité 29 sept. 2026
pytest-dev/pytest-mock

2 k

étoiles

174

forks

10

issues ouvertes

hacktoberfestmockpytest

Ce README est souvent en anglais.

pytest-mock

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.

Projets similaires

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

Pythonhacktoberfestpythontest
Ppytest-dev
14,5 k étoiles3,4 k

Most popular Mocking framework for unit tests written in Java

Javajavajava-librarymock
Mmockito
15,5 k étoiles2,7 k

mocking library for Kotlin

Kotlinargument-matcherschain-callshacktoberfest
Mmockk
5,8 k étoiles420