{"id":27742,"library":"flake8-mock-spec","title":"flake8-mock-spec","description":"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.","status":"active","version":"1.4.0","language":"python","source_language":"en","source_url":"https://github.com/plannigan/flake8-mock-spec","tags":["flake8","plugin","mock","testing","linting"],"install":[{"cmd":"pip install flake8-mock-spec","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required plugin host","package":"flake8","optional":false}],"imports":[{"note":"Plugin is auto-loaded by flake8; no manual import needed","symbol":"flake8_mock_spec","correct":"from flake8_mock_spec import *"}],"quickstart":{"code":"# Install the plugin\n# pip install flake8-mock-spec\n# Then run flake8 on your code:\n# flake8 myproject/\n\n# Example of a lint violation (W8001):\nmock = Mock()  # W8001: mock with no spec\n\n# Correct way:\nmock = Mock(spec=SomeClass)","lang":"python","description":"Run flake8 after installing the plugin to catch missing spec arguments in mock constructors."},"warnings":[{"fix":"Ensure you also manually check patches; use spec parameter in patch calls where appropriate.","message":"The 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to the latest version and ensure Python >=3.8.1.","message":"As 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.","severity":"deprecated","affected_versions":"<1.4.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Add spec=YourClass to the mock constructor, e.g., Mock(spec=MyClass).","cause":"The plugin flags any call to Mock(), MagicMock(), or NonCallableMock() without the spec argument.","error":"W8001 mock with no spec"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}