Skip to main content

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.

Installation

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

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

Plugin for Flake8

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

$ flake8 --version
3.5.0 (verve-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 (25-04-2019)

  • Forked by Verve to verve-flake8-mock

  • 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 verve-flake8-mock 0.4

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

Source distribution (sdist)

Source distribution for verve-flake8-mock 0.4
File Size Uploaded
verve-flake8-mock-0.4.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for verve-flake8-mock 0.4
File Interpreter ABI Platform
verve_flake8_mock-0.4-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release files / verve-flake8-mock-0.4.tar.gz

Download URL verve-flake8-mock-0.4.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
97186314b0a86e5127b60b12437640dbf688a32c5d0f2d2d74b13184b222a001
BLAKE2b-256 checksum
How to use checksums
b2b2f88d6cdbe802013da06d0f701925b6c45235b03304980c781d377a92208e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release files / verve_flake8_mock-0.4-py3-none-any.whl

Download URL verve_flake8_mock-0.4-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62faf9caed7346111313515a8a119312ddb05d667593e841b4d2286c7f0ee3fb
BLAKE2b-256 checksum
How to use checksums
422e49207f913b4369b7a7eef5b7e320440dda0b6fb331cf3a38e36a7b75b962
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.4 This release

2 release files

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