Skip to main content

Python project: mockbuster

Project description

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

Development

# Install dependencies
uv sync

# Run tests
uv run pytest

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mockbuster-0.1.1.tar.gz (181.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mockbuster-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file mockbuster-0.1.1.tar.gz.

File metadata

  • Download URL: mockbuster-0.1.1.tar.gz
  • Upload date:
  • Size: 181.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mockbuster-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f921c8c1ab5df555d4fc07ef8efd43c00d6cf7ee938794f4f2f2cae833abe659
MD5 f25d1807dc4fa6a46cf22dc8c3a0b243
BLAKE2b-256 9aa8e68418b29c94882f7aefa3babffc77dd4c5af4174a40902b3d9401ee7ed8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mockbuster-0.1.1.tar.gz:

Publisher: ci.yml on benomahony/mockbuster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mockbuster-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mockbuster-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mockbuster-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3df90d1703ba1243c08f9e4a5af917670d2aefa72ac740b87fcce97137f2af0
MD5 6a39e9187b00abb3d6c1ba27d9e6e6db
BLAKE2b-256 3fba7bc8f0349d12c67890dcd5cb9cb6bb3671647f2b074fff98e8d32b19e788

See more details on using hashes here.

Provenance

The following attestation bundles were made for mockbuster-0.1.1-py3-none-any.whl:

Publisher: ci.yml on benomahony/mockbuster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page