Skip to main content

Flake8 Mock plugin

Remember that a mock’s job is to say, “You got it, boss” whenever anyone calls it. It will do real work, like raising an exception, when one of its convenience methods is called, like assert_called_once_with. But it won’t do real work when you call a method that only resembles a convenience method, such as assert_called_once (no _with!). Sometimes developers may not notice that they are using a non-existent mock method, because they are not getting an output error telling them so. And for some reason they can also forget to verify that the test cases fail before writing implementation code.

This plugin checks for possible non-existent mock methods when you run flake8, the Python code checker.

Inspired by http://engineeringblog.yelp.com/2015/02/assert_called_once-threat-or-menace.html.

Includes edits from

Installation

You can install or upgrade flake8-mock with these commands:

$ pip install flake8-mock
$ pip install --upgrade flake8-mock

Plugin for Flake8

When both flake8 3.5.0 and flake8-mock are installed, the plugin is available in flake8:

$ flake8 --version
3.5.0 (flake8-mock: 0.4, pyflakes: 0.8.1)

Example output

Once you run flake8, you can have something like:

$ flake8 test_file.py
test_file.py:55:5: M201 called_once is a non-existent mock property
test_file.py:56:5: M200 called_once_with is a non-existent mock method

Credits

  • Alejandro Gabriel Pereira is the original author.

  • Ania Warzecha has rewritten it for flake8 3 and with support for more methods

Changes

0.4 (24-11-2018)

  • Added has_calls to checked methods

  • Added a check for not existent properties on mocks

  • Added compatibility for flake8 3.x

  • Added tests

0.3 (09-10-2016)

  • Don’t warn on assert_not_called, assert_called or assert_called_once.

  • Use ASCII only in README.rst

0.2 (12-16-2015)

  • Add Python 3 compatibility.

0.1 (10-20-2015)

  • First release.

0.1dev0 (10-19-2015)

  • First dev release.

Metadata

Release files for flake8-mock-x2 0.4.1

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

Source distribution (sdist)

Source distribution for flake8-mock-x2 0.4.1
File Size Uploaded Provenance Actions
flake8-mock-x2-0.4.1.tar.gz 10.3 kB Without provenance Details for flake8-mock-x2-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flake8-mock-x2 0.4.1
File Interpreter ABI Platform Actions
flake8_mock_x2-0.4.1-py3-none-any.whl Python 3 none any Details for flake8_mock_x2-0.4.1-py3-none-any.whl

Total release size: 20.9 kB

Release files / flake8-mock-x2-0.4.1.tar.gz

Download URL flake8-mock-x2-0.4.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e28e1c6ff91c35d960a9a04c602ab8ca4d49837c892cb58d13cf5e669a2a7da2
BLAKE2b-256 checksum
How to use checksums
5f5224e82e4d871506e735f3d6b655aef5488402b781bfa430cfa82e25f0301a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / flake8_mock_x2-0.4.1-py3-none-any.whl

Download URL flake8_mock_x2-0.4.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e7b7baf15b7ef561aedf32e88bf0accbf3551546ac91aeceaf541aa5d42e8ac
BLAKE2b-256 checksum
How to use checksums
d3ecd239cb93d471e864c1717bc71c3722155f467981580bd6fddcf1b16b26f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Security for flake8-mock-x2 0.4.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files No provenance

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