Registry / testing / flake8-mock-spec

flake8-mock-spec

JSON →
library1.4.0pypypi✓ verified 85d ago

A flake8 plugin that ensures mocks are constructed with the `spec` argument, preventing fragile tests. Version 1.4.0 supports Python 3.8+ and requires flake8. It has a release cadence of roughly once a year.

pip install flake8-mock-spec
INSTALL
IMPORT
SIG · FLAKE8-MOCK-SPEC
F
flake8-mock-spec
testingpythonv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flake8_mock_spec
from flake8_mock_spec import *
Plugin is auto-loaded by flake8; no manual import needed

Run flake8 after installing the plugin to catch missing spec arguments in mock constructors.

# Install the plugin # pip install flake8-mock-spec # Then run flake8 on your code: # flake8 myproject/ # Example of a lint violation (W8001): mock = Mock() # W8001: mock with no spec # Correct way: mock = Mock(spec=SomeClass)
Debug
Known issues
gotchaThe plugin only flags mock.Mock, mock.MagicMock, and mock.NonCallableMock calls without a spec argument. It does not check patched objects (e.g., patch('module.ClassName')) or other mock library variants.
fix
Ensure you also manually check patches; use spec parameter in patch calls where appropriate.
affects: all
deprecatedAs of version 1.4.0, the plugin is compatible with Python 3.8+ and flake8 4+; older Python versions (3.6, 3.7) are not supported.
fix
Upgrade to the latest version and ensure Python >=3.8.1.
affects: <1.4.0
Errors
Common errors & fixes
W8001 mock with no spec
The plugin flags any call to Mock(), MagicMock(), or NonCallableMock() without the spec argument.
fix
Add spec=YourClass to the mock constructor, e.g., Mock(spec=MyClass).
Upgrade
Version history
1.4.0latest on PyPI · released Jan 14, 2023
Audit
Dependencies
flake8requiredRequired plugin host
Agent activity
5 hits · last 30 days
node
4
Resources
flake8-mock-spec — pip install flake8-mock-spec · libregistry