pytest-mock is a thin wrapper around mock.

mock is since python 3.3. actually the same as unittest.mock.

I don't know if mocker is another library, I only know it as the name of the fixture provided by pytest-mock to get mocking done in your tests.

I personally use pytest and pytest-mock for my tests, which allows you to write very concise tests like

from pytest_mock import MockerFixture

@pytest.fixture(autouse=True)
def something_to_be_mocked_everywhere(mocker):
    mocker.patch()


def tests_this(mocker: MockerFixture):
    mocker.patch ...
    a_mock = mocker.Mock() ...
    ...

But this is mainly due to using fixtures, which is already pointed out is what pytest-mock offers.

Answer from Simon Hawe on Stack Overflow
🌐
PyPI
pypi.org › project › pytest-mock
pytest-mock · PyPI
Thin-wrapper around the mock package for easier use with pytest
🌐
Readthedocs
pytest-mock.readthedocs.io
pytest-mock documentation
This pytest plugin provides a mocker fixture which is a thin-wrapper around the patching API provided by the mock package:
Discussions

python - What are the differences between unittest.mock, mock, mocker and pytest-mock? - Stack Overflow
I am new to Python development, I am writing test cases using pytest where I need to mock some behavior. Googling best mocking library for pytest, has only confused me. I have seen unittest.mock, m... More on stackoverflow.com
🌐 stackoverflow.com
pytest-mock : Mocking in pytest - Test & Code
I just finished listening to your podcast episode featuring Michael Foord (linked from the episode in this post), discussing testing and mocks. Since his recent passing, it was really nice to hear his distinctive voice again. Great job on that 👍 More on reddit.com
🌐 r/Python
4
90
February 4, 2025
pytest mock doesn't work as I expected
You aren’t calling foo_bar.foo; you are calling foo (your global variable, not the module attribute). Names matter when patching, even if both unpatched names refer to the same object. If you are using from foo_bar import foo, you need to patch foo. If you were just using import foo_bar and calling foo_bar.foo, your patch would be correct. More on reddit.com
🌐 r/learnpython
9
6
December 1, 2025
pytest mock
pytest-mock is a wrapper around unittest.mock, there's only small differences in the interface. IMO, it's important not to dwell on tiny differences like what framework to use for testing or mocking because the bigger questions are: What should you test and how should you structure it? What should you mock and how should you mock it? How can you structure your code to be more testable and need less mocking? (which tends to result in a greater degree of configurability, to boot) All of that said, pytest and its many plugins (including pytest-mock) are my go to. More on reddit.com
🌐 r/Python
28
58
December 28, 2023
🌐
GitHub
github.com › pytest-dev › pytest-mock
GitHub - pytest-dev/pytest-mock: Thin-wrapper around the mock package for easier use with pytest · GitHub
This plugin provides a mocker fixture which is a thin-wrapper around the patching API provided by the mock package:
🌐
Medium
medium.com › analytics-vidhya › pytest-mocking-cheatsheet-dcebd84876e3
Pytest mocking cheatsheet. Ello, ello, ello my fellow engineers! | by AlexV | Analytics Vidhya | Medium
January 5, 2023 - We can utilise what we have previously learnt and add the the following fixtures to conftest.py file to help mock the above system: """conftest.py"""import pytest from flask import Flask from flask_sqlalchemy import SQLAlchemy from functions_to_mock.functions import MyModel # This fixture will mock your DB table model @pytest.fixture def mock_my_model(): my_model = MyModel( id="my_mock_id", ) return my_model # This fixture will mock the SQLAlchemy query response from the DB @pytest.fixture def mock_get_sqlalchemy(mocker): mock = mocker.patch("flask_sqlalchemy._QueryProperty.__get__").return_value = mocker.Mock() return mock #This fixture will mock your flask application @pytest.fixture def flask_app_mock(): """Flask application mock set up.""" app_mock = Flask(__name__) db = SQLAlchemy(app_mock) db.init_app(app_mock) return app_mock
🌐
pytest
docs.pytest.org › en › stable › how-to › monkeypatch.html
How to monkeypatch/mock modules and environments - pytest documentation
This mock can be shared across tests using a fixture: # contents of test_app.py, a simple test for our API retrieval import pytest import requests # app.py that includes the get_json() function import app # custom class to be the mock return value of requests.get() class MockResponse: @staticmethod def json(): return {"mock_key": "mock_response"} # monkeypatched requests.get moved to a fixture @pytest.fixture def mock_response(monkeypatch): """Requests.get() mocked to return {'mock_key':'mock_response'}.""" def mock_get(*args, **kwargs): return MockResponse() monkeypatch.setattr(requests, "get", mock_get) # notice our test uses the custom fixture instead of monkeypatch directly def test_get_json(mock_response): result = app.get_json("https://fakeurl") assert result["mock_key"] == "mock_response"
Find elsewhere
🌐
OneUptime
oneuptime.com › home › blog › how to use pytest with mocking
How to Use pytest with Mocking
February 2, 2026 - The mocker fixture provided by pytest-mock simplifies mocking in tests.
🌐
Medium
medium.com › @bfortuner › python-unit-testing-with-pytest-and-mock-197499c4623c
Python unit testing with Pytest and Mock | by Brendan Fortuner | Medium
June 1, 2017 - Here are some examples I developed while contributing to the Neuroscience research platform BigNeuron. I’ve renamed the methods for clarity, but the original code can be found here: module and tests. (I’m actually using a wrapper library called Pytest-mock instead of plain Mock).
🌐
DEV Community
dev.to › waylonwalker › pytest-mock-basics-24io
pytest-mock Basics - DEV Community
March 14, 2022 - You can install pytest-mock, use the mocker fixture, and patch objects methods with what you want them to be.
🌐
DataCamp
datacamp.com › tutorial › pytest-mock
pytest-mock Tutorial: A Beginner’s Guide to Mocking in Python | DataCamp
December 18, 2024 - By the end of this tutorial, you will be ready to add mocking techniques to your test cases, making them more powerful. pytest-mock is a plugin for the popular Python testing framework pytest that provides easy access to mocking capabilities.
🌐
Thedatasavvycorner
thedatasavvycorner.com › blogs › 15-pytest-mocking
Mocking With Pytest in Plain English – The Data Savvy Corner
July 14, 2024 - In order to test their source code that depends on these services, developers need to replace the properties of these services when the test suite runs. Injecting replacement values into the code at runtime is generally referred to as mocking.
🌐
GitHub
github.com › pytest-dev › pytest-mock › releases
Releases · pytest-dev/pytest-mock
Thin-wrapper around the mock package for easier use with pytest - pytest-dev/pytest-mock
🌐
Reddit
reddit.com › r/python › pytest-mock : mocking in pytest - test & code
r/Python on Reddit: pytest-mock : Mocking in pytest - Test & Code
February 4, 2025 -

https://testandcode.com/episodes/pytest-mock

pytest-mock is currently the #3 pytest plugin.

  • Why the pytest-mock plugin is awesome

  • What is mocking, patching, and monkey patching

  • What, if any, is the difference between mock, fake, spy, stub.

  • Why we might need these in testing

  • Some history of mock in Python and how mock became unittest.mock

  • Using mocker.patch, mocker.spy, and mocker.stub

  • Why pytest-mock is awesome and why you might want to use it over straight unittest.mock

🌐
Python
docs.python.org › 3 › library › unittest.mock.html
unittest.mock — mock object library
It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
🌐
Reddit
reddit.com › r/learnpython › pytest mock doesn't work as i expected
r/learnpython on Reddit: pytest mock doesn't work as I expected
December 1, 2025 -

Hi everyone, I am trying to mock a return value of a function using pytest mock. I have the following files:

# foo_bar.py
def foo():
    return 5

def bar():
    return foo()
# test_foo_bar.py
from pytest_mock import MockFixture
from foo_bar import bar, foo

def test_foo(mocker: MockFixture):
    assert foo() == 5
    mocker.patch("foo_bar.foo", return_value=10)
    assert foo() == 10


def test_bar(mocker: MockFixture):
    assert bar() == 5
    mocker.patch("foo_bar.foo", return_value=10)
    assert bar() == 10

When I run the above test, test_bar passes, but test_foo fails on assert foo() == 10

Why is it so? Thanks

🌐
Readthedocs
pytest-mock.readthedocs.io › en › latest › usage.html
Usage - pytest-mock documentation
The object returned by mocker.spy is a pytest_mock.SpyType object which subclasses MagicMock, so all standard checking functions are available (like assert_called_once_with or call_count in the examples above), in addition to four extra attributes:
🌐
YouTube
youtube.com › watch
Mocking in Pytest | Pytest Mocking Tutorial - YouTube
Full Testing Course: https://youtu.be/DDaMBjeEN4Q?si=DYREJJOyB0xTMIQQFull Python Course: https://youtu.be/swjWq7cyq14?si=jTAjjpz9Agzv0T5UPython OOP Course: ...
Published: July 18, 2024
🌐
Readthedocs
pytest-mock.readthedocs.io › en › latest › remarks.html
Remarks - pytest-mock documentation
test functions must receive the mock objects as parameter, even if you don’t plan to access them directly; also, order depends on the order of the decorated patch functions;
🌐
GitHub
github.com › pytest-dev › pytest-mock › activity
Activity · pytest-dev/pytest-mock
April 7, 2026 - Thin-wrapper around the mock package for easier use with pytest - Activity · pytest-dev/pytest-mock
Author: pytest-dev
🌐
Pytest with Eric
pytest-with-eric.com › introduction › fixture-mocker-not-found
How To Easily Resolve The "Fixture 'Mocker' Not Found" ...
March 23, 2026 - As silly as this sounds, misspelling the fixture name- using mock instead of mocker can cause issues. Once you’ve installed pytest-mock, you don’t need to import it explicitly in your test files.