Skip to main content

mockbuster

A Python linter that detects and reports all uses of mocking in test files.

Installation

pip install mockbuster

Usage

As a library

Detect mocking usage in Python code:

from mockbuster import detect_mocks

code = """
from unittest.mock import Mock

def test_foo():
    mock_obj = Mock()
    assert mock_obj is not None
"""

violations = detect_mocks(code)
assert len(violations) == 1
assert violations[0]["line"] == 2
assert "unittest.mock" in violations[0]["message"]

Detect patch decorator usage:

from mockbuster import detect_mocks

code = """
from unittest.mock import patch

@patch('some.module')
def test_bar(mock_module):
    pass
"""

violations = detect_mocks(code)
assert len(violations) == 1
assert violations[0]["line"] == 2
assert "patch" in violations[0]["message"]

Detect pytest-mock usage:

from mockbuster import detect_mocks

code = """
def test_baz(mocker):
    mocker.patch('some.module')
"""

violations = detect_mocks(code)
assert len(violations) == 1
assert violations[0]["line"] == 2
assert "mocker" in violations[0]["message"]

Detect MagicMock usage:

from mockbuster import detect_mocks

code = """
from unittest.mock import MagicMock

def test_qux():
    magic = MagicMock()
"""

violations = detect_mocks(code)
assert len(violations) == 1

Clean code with no mocking returns empty list:

from mockbuster import detect_mocks

code = """
def test_clean():
    result = 1 + 1
    assert result == 2
"""

violations = detect_mocks(code)
assert len(violations) == 0

As a CLI

Scan a single file:

mockbuster tests/test_example.py

Scan a directory:

mockbuster tests/

Exit with error code if mocks found:

mockbuster tests/ --strict

Configuration

Opt specific categories out of detection via [tool.mockbuster] in your project's pyproject.toml:

[tool.mockbuster]
disable = ["fixtures"]   # still catches Mock() and patch()

Valid category names:

Category What it controls
mock_classes Mock(), MagicMock(), AsyncMock(), etc. instantiations
patch @patch decorators, patch() calls, with patch(...):
fixtures mocker and monkeypatch function arguments

You can also disable categories at runtime with --disable (repeatable):

mockbuster tests/ --disable fixtures
mockbuster tests/ --disable mock_classes --disable patch

CLI flags are merged with any pyproject.toml config.

Baseline

Suppress existing violations so CI only catches new ones:

mockbuster tests/ --update-baseline   # record current state
git add .mockbuster-baseline.json     # commit it
mockbuster tests/ --strict            # CI: only new violations fail the build

Development

# Install dependencies
uv sync

# Run tests
uv run pytest

# Run pre-commit hooks
uv run pre-commit run --all-files

Metadata

Release files for mockbuster 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mockbuster 0.1.4
File Size Uploaded Provenance Actions
mockbuster-0.1.4.tar.gz 207.0 kB With provenance Details for mockbuster-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mockbuster 0.1.4
File Interpreter ABI Platform Actions
mockbuster-0.1.4-py3-none-any.whl Python 3 none any Details for mockbuster-0.1.4-py3-none-any.whl

Total release size: 218.4 kB

Release files / mockbuster-0.1.4.tar.gz

Download URL mockbuster-0.1.4.tar.gz
Size 207.0 kB
Tags Source
SHA-256 checksum
How to use checksums
58a01433182a56914b98422d5d5b0783b138145421dff244289a3889acc10da1
BLAKE2b-256 checksum
How to use checksums
bab6e270f5e06f474cd1384874d5440a113a589d0297c764af9c60aa9ad4496d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Release files / mockbuster-0.1.4-py3-none-any.whl

Download URL mockbuster-0.1.4-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eef70d6e0eea4c9e28b6c17879bb2476b4ad4fc2713dd81177b9d735be85dfe0
BLAKE2b-256 checksum
How to use checksums
4b4d4c4084a1ccbeed49f42e553db97676adca2357fd8511356a4a6ee9a88722
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

Security for mockbuster 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mockbuster-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page