Stage 02 · Test · Researched comparison
Best Python Mocking Libraries in 2026
unittest.mock is the first pick for most teams because it ships with Python and needs no install. pytest-mock suits projects already using pytest and wanting a cleaner fixture-based API. responses is the better fit when you mainly mock HTTP calls made with the requests library, and VCR.py helps when you want to record real HTTP traffic once and replay it in tests.
By Shihab Mia
Published 22 Nov 2026 · 6 tools compared
We run no ads and no affiliate links at launch. The order of a list follows our published method. See how we score.
Prices are the starting prices vendors list publicly. Plans change, so confirm the current price on the vendor page before you buy.
Key takeaways
- unittest.mock and pytest-mock are free and open source, so there is no licence cost to mock objects or functions.
- responses and VCR.py target HTTP layer testing; they do not replace general-purpose object mocking.
- freezegun and time-machine control the clock, which unittest.mock does not do on its own.
- All picks run locally in your test process, so no test data is sent to a third-party web page.
Who each pick is for
- General object and function mocking with no extra installunittest.mock
- pytest users who want a mocker fixture around unittest.mockpytest-mock
- Stubbing HTTP calls made with the requests libraryresponses
- Recording real HTTP traffic and replaying it in testsVCR.py
- Freezing and traveling the clock in testsfreezegun
- Fast clock control with travel and tick helperstime-machine
Comparison
| Tool | Best for | Standout feature | Listed starting price | Free plan or trial |
|---|---|---|---|---|
| 1unittest.mock | General object and function mocking with no extra install | Ships with Python | Free (open source) | Free plan |
| 2pytest-mock | pytest users who want a mocker fixture around unittest.mock | Single mocker fixture | Free (open source) | Free plan |
| 3responses | Stubbing HTTP calls made with the requests library | Registers expected responses by URL and method | Free (open source) | Free plan |
| 4VCR.py | Recording real HTTP traffic and replaying it in tests | Records cassettes once and replays them offline | Free (open source) | Free plan |
| 5freezegun | Freezing and traveling the clock in tests | freeze_time decorator and context manager | Free (open source) | Free plan |
| 6time-machine | Fast clock control with travel and tick helpers | Patches time at the C level for broad coverage | Free (open source) | Free plan |
How we picked
We picked libraries that are actively maintained and genuinely serve a mocking or test-double job in Python. Criteria were fit for the task, supported platforms and Python versions, licence and price, whether code runs locally, and documented limits. Sources were official documentation, project repositories and public licence pages. Prices and licences can change, so confirm details on each project site before you commit.
The tools, one by one
unittest.mock
Best for general object and function mocking with no extra install

What it is and where it fits
unittest.mock is part of the Python standard library. It provides Mock and MagicMock objects, the patch decorator and context manager, and helpers like autospec and call assertions. Because it is bundled, you can start mocking without adding a dependency or changing your install process.
It works on any platform that runs CPython, and it is maintained as part of CPython itself, so its release cycle follows Python versions. There is no paid tier. The main limits are ergonomic: patch targets can be easy to get wrong, and the decorator stacking gets noisy in larger test files. Teams that want fixtures and a shorter syntax often pair it with pytest-mock. Skip it only if you need HTTP recording or frozen time, which require separate libraries.
Standout: Ships with Python
Free (open source), as listed by the vendor (unittest.mock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Ships with Python
- supports patching, autospec and call assertions
Drawbacks
- Verbose decorator and context-manager syntax
- no built-in HTTP or time helpers
Skip it if this limit matters to you: verbose decorator and context-manager syntax.
Verdict. A sensible pick for general object and function mocking with no extra install.
Alternatives in this guide: pytest-mock, responses, VCR.py
pytest-mock
Best for pytest users who want a mocker fixture around unittest.mock

What it is and where it fits
pytest-mock is a pytest plugin that wraps unittest.mock in a mocker fixture. You call mocker.patch, mocker.patch.object or mocker.spy inside a test, and the plugin reverts the patches when the test ends. That removes most manual cleanup and the need to stack decorators.
It runs wherever pytest runs and is distributed under the MIT licence. The plugin does not add new mocking concepts; it simplifies the existing ones, so anyone who knows unittest.mock can move over quickly. It is a poor fit for projects on unittest or nose2 that do not use pytest. If your suite is already pytest-based and you mock objects often, this is usually the least disruptive upgrade.
Standout: Single mocker fixture
Free (open source), as listed by the vendor (pytest-mock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Single mocker fixture
- automatically undoes patches after each test
Drawbacks
- Requires pytest
- still relies on unittest.mock semantics under the hood
Skip it if this limit matters to you: requires pytest.
Verdict. A sensible pick for pytest users who want a mocker fixture around unittest.mock.
Alternatives in this guide: unittest.mock, responses, VCR.py
responses
Best for stubbing HTTP calls made with the requests library

What it is and where it fits
responses is a library for mocking out the requests library in tests. You register a response for a URL and method, run the code, and responses raises an error if an expected call was not made. It supports status codes, headers, bodies, callbacks and ordered or unordered matching.
It runs in any Python test runner and is released under the Apache 2.0 licence. The key limit is scope: it patches requests specifically, so code using httpx, aiohttp or urllib needs a different tool. It is also not a general object mocker, so you still need unittest.mock or pytest-mock for non-HTTP dependencies. Teams with a requests-heavy client layer get the most from it.
Standout: Registers expected responses by URL and method
Free (open source), as listed by the vendor (responses website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Registers expected responses by URL and method
- asserts that calls were made
Drawbacks
- Tied to requests
- does not cover httpx, aiohttp or urllib directly
Skip it if this limit matters to you: tied to requests.
Verdict. A sensible pick for stubbing HTTP calls made with the requests library.
Alternatives in this guide: unittest.mock, pytest-mock, VCR.py
VCR.py
Best for recording real HTTP traffic and replaying it in tests

What it is and where it fits
VCR.py records HTTP interactions to cassette files and replays them on later runs. It works with requests, urllib3, httpx and aiohttp through its own patching layer. Tests then run without network access, which makes them faster and more stable than hitting live services.
It is open source under the MIT licence and runs on standard Python. The tradeoff is maintenance: cassettes are files you commit, and they go stale when an API changes. Recorded headers and bodies can include tokens or personal data, so scrub them before committing. Use it when you need realistic HTTP fixtures; prefer responses when you want explicit, hand-written stubs instead.
Standout: Records cassettes once and replays them offline
Free (open source), as listed by the vendor (VCR.py website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Records cassettes once and replays them offline
- supports several HTTP clients
Drawbacks
- Cassettes need review and refresh
- recorded data can contain sensitive values
Skip it if this limit matters to you: cassettes need review and refresh.
Verdict. A sensible pick for recording real HTTP traffic and replaying it in tests.
Alternatives in this guide: unittest.mock, pytest-mock, responses
freezegun
Best for freezing and traveling the clock in tests

What it is and where it fits
freezegun patches datetime, date, time and related calls so tests see a fixed clock. You can freeze at a specific moment, move time forward with tick, or travel to a new date mid-test. This covers expiry logic, scheduling and date formatting that object mocks handle awkwardly.
It is open source under the Apache 2.0 licence and runs on standard Python. The known limits are edge cases: some C-level or third-party time sources are not patched, and threaded code needs attention. For very tight control some teams use time-machine instead. Pick freezegun when you want a readable freeze_time API and broad coverage of the common datetime paths.
Standout: freeze_time decorator and context manager
Free (open source), as listed by the vendor (freezegun website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- freeze_time decorator and context manager
- supports time travel and tick
Drawbacks
- Can miss code that reads time through C extensions
- needs care with threads
Skip it if this limit matters to you: can miss code that reads time through C extensions.
Verdict. A sensible pick for freezing and traveling the clock in tests.
Alternatives in this guide: unittest.mock, pytest-mock, responses
time-machine
Best for fast clock control with travel and tick helpers

What it is and where it fits
time-machine is a library for mocking the current date and time in tests. It patches the C-level time functions, which catches more call sites than pure-Python patching. You use travel to move the clock and tick to advance it, and the change is undone when the context exits.
It is open source under the MIT licence and installs from PyPI. It works with pytest and unittest alike. The main limit is that it focuses only on time; you still need unittest.mock or pytest-mock for other dependencies. It is a good pick when freezegun misses a time source, or when you want a small, single-purpose clock helper.
Standout: Patches time at the C level for broad coverage
Free (open source), as listed by the vendor (time-machine website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Patches time at the C level for broad coverage
- simple travel and tick API
Drawbacks
- Smaller ecosystem than freezegun
- still not a general object mocker
Skip it if this limit matters to you: smaller ecosystem than freezegun.
Verdict. A sensible pick for fast clock control with travel and tick helpers.
Alternatives in this guide: unittest.mock, pytest-mock, responses
Who should use what
If you mock plain objects and functions and want zero dependencies, start with unittest.mock. If your suite already runs on pytest and you want shorter patch syntax, add pytest-mock. If most of your test doubles are HTTP calls with requests, use responses; if you need recorded fixtures across several HTTP clients, use VCR.py. For date and time logic, choose freezegun or time-machine.
Questions to settle before you buy
What to check before you buy
- Confirm the library supports your Python version and test runner.
- Check the licence fits your project, especially for commercial code.
- Verify the library covers the layer you mock: objects, HTTP or time.
- Make sure patches are undone after each test to avoid order-dependent failures.
- Review any recorded fixtures for secrets or personal data before committing them.
FAQ
Is unittest.mock enough on its own?
For many projects, yes. It covers object and function mocking with no install. You only need extra libraries for HTTP stubbing or clock control.
Do I need pytest-mock if I already use unittest.mock?
No. pytest-mock is a convenience wrapper. Add it if you want a mocker fixture and automatic cleanup; otherwise unittest.mock works fine inside pytest.
What is the difference between responses and VCR.py?
responses registers hand-written stubs for requests calls. VCR.py records real HTTP traffic to cassette files and replays it. Use responses for explicit stubs and VCR.py for realistic recorded fixtures.
Can these libraries mock time zones and dates?
freezegun and time-machine control the clock and are the usual picks for date logic. unittest.mock can patch datetime calls manually, but the dedicated libraries are less error-prone.
Are these mocking libraries free?
All six listed here are free and open source. Each has its own licence, such as MIT or Apache 2.0, so check the terms for your use case.
Sources we checked
Method: how we score · editorial policy.
Change log. First published 22 Nov 2026.