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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mockbuster-0.1.2.tar.gz.
File metadata
- Download URL: mockbuster-0.1.2.tar.gz
- Upload date:
- Size: 181.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
872850c70e304f01b7e3e81f43f2e76f5ad1285ea8be49a26a3161ce6e76a3b2
|
|
| MD5 |
f95c3208a5396a544ebf05f85a69e6a2
|
|
| BLAKE2b-256 |
15b840c05a45ad39375bb976766fb91095387665c95187a3a5103dd05b70d238
|
Provenance
The following attestation bundles were made for mockbuster-0.1.2.tar.gz:
Publisher:
ci.yml on benomahony/mockbuster
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mockbuster-0.1.2.tar.gz -
Subject digest:
872850c70e304f01b7e3e81f43f2e76f5ad1285ea8be49a26a3161ce6e76a3b2 - Sigstore transparency entry: 909695395
- Sigstore integration time:
-
Permalink:
benomahony/mockbuster@03dcf8ea8c0dd1bc717e49e4992c50208e2f42e5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/benomahony
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@03dcf8ea8c0dd1bc717e49e4992c50208e2f42e5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mockbuster-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mockbuster-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0390ab42eb4d88948a0329d7cc0b74c9e0ca1a376b09e59eda28a7a989ef742b
|
|
| MD5 |
a09003d58c59010aba84de2c41fce88e
|
|
| BLAKE2b-256 |
274f1c6fd36e2254ae7c286176371325ae3f132da358138c5c43fd7d9abe77f8
|
Provenance
The following attestation bundles were made for mockbuster-0.1.2-py3-none-any.whl:
Publisher:
ci.yml on benomahony/mockbuster
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mockbuster-0.1.2-py3-none-any.whl -
Subject digest:
0390ab42eb4d88948a0329d7cc0b74c9e0ca1a376b09e59eda28a7a989ef742b - Sigstore transparency entry: 909695399
- Sigstore integration time:
-
Permalink:
benomahony/mockbuster@03dcf8ea8c0dd1bc717e49e4992c50208e2f42e5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/benomahony
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@03dcf8ea8c0dd1bc717e49e4992c50208e2f42e5 -
Trigger Event:
push
-
Statement type: