pytest-mock-guide
pytest-mock Usage Guide
pytest-mock is a pytest plugin providing a mocker fixture as a thin wrapper around Python's unittest.mock patching API. It automatically undoes all mocking at the end of each test.
The mocker Fixture
The mocker fixture is the main interface. Request it in your test function:
def test_example(mocker):
# All mocks are automatically cleaned up after this test
mock_func = mocker.patch("module.function")
Available Fixture Scopes
| Fixture | Scope | Use Case |
|---|---|---|
mocker |
function | Default, per-test mocking |
More from bossjones/boss-file-utils
httpx
A next-generation HTTP client for Python with both sync and async support, perfect for modern Python applications
1pydantic
Data validation and settings management using Python type annotations with Pydantic v2
1pytest
Python testing framework for writing simple, scalable, and powerful tests
1alembic
Database migration management for SQLAlchemy projects using Alembic
1uvicorn
ASGI server for Python web applications - Fast, production-ready server for async frameworks
1apscheduler
Advanced Python Scheduler - Task scheduling and job queue system
1