Skip to main content

Flake8 unittest assert method checker

Project description

PyPI Version Python Versions

flake8-assertive is a Flake8 extension that encourages using more specific unittest assertions beyond just the typical assertEqual(a, b) and assertTrue(x) methods. The alternate methods suggested by this extension perform more precise checks and provide better failure messages than the generic methods.

Original

Suggestion

Code

assertTrue(a == b)

assertEqual(a, b)

A500

assertTrue(a != b)

assertNotEqual(a, b)

A500

assertFalse(a == b)

assertNotEqual(a, b)

A500

assertFalse(a != b)

assertEqual(a, b)

A500

assertTrue(a < b)

assertLess(a, b)

A500

assertTrue(a <= b)

assertLessEqual(a, b)

A500

assertTrue(a > b)

assertGreater(a, b)

A500

assertTrue(a >= b)

assertGreaterEqual(a, b)

A500

assertTrue(a is b)

assertIs(a, b)

A501

assertTrue(a is not b)

assertIsNot(a, b)

A501

assertFalse(a is b)

assertNotIs(a, b)

A501

assertFalse(a is not b)

assertIs(a, b)

A501

assertTrue(a in b)

assertIn(a, b)

A501

assertFalse(a in b)

assertNotIn(a, b)

A501

assertTrue(isinstance(a, b))

assertIsInstance(a, b)

A501

assertFalse(isinstance(a, b))

assertNotIsInstance(a, b)

A501

assertEqual(a, None)

assertIsNone(a)

A502

assertNotEqual(a, None)

assertIsNotNone(a)

A502

assertTrue(a is None)

assertIsNone(a)

A502

assertTrue(a is not None)

assertIsNotNone(a)

A502

assertFalse(a is None)

assertIsNotNone(a)

A502

assertFalse(a is not None)

assertIsNone(a)

A502

assertEqual(a, True)

assertTrue(a)

A502

assertEqual(a, False)

assertFalse(a)

A502

Note that some suggestions are normalized forms of the original, such as when a double-negative is used (assertFalse(a != b)assertEqual(a, b)). There aren’t suggestions for things like assertFalse(a > b), which may or may not be equivalent to assertLessEqual(a, b).

Installation

Install from PyPI using pip:

$ pip install flake8-assertive

The extension will be activated automatically by flake8. You can verify that it has been loaded by inspecting the flake8 --version string.

$ flake8 --version
3.5.0 (assertive: 1.0.0, ...) CPython 2.7.15 on Darwin

Error Codes

This extension adds three new error codes (using the A50 prefix):

  • A500: prefer {func} for ‘{op}’ comparisons

  • A501: prefer {func} for ‘{op}’ expressions

  • A502: prefer {func} instead of comparing to {obj}

Configuration

Configuration values are specified in the [flake8] section of your config file or as command line arguments (e.g. --assertive-snakecase).

  • assertive-snakecase: suggest snake_case assert method names (e.g. assert_true()) instead of the standard names (e.g. assertTrue())

  • assertive-test-pattern: fnmatch pattern for identifying unittest test files (and all other files will be skipped)

Changes

1.0.0 (2018-06-04)

  • Suggest assertIsNone(a) for assertTrue(a is None), etc.

  • Recognize assertEquals() and assertNotEquals() as aliases for assertEqual() and assertNotEqual().

0.9.0 (2018-05-14)

  • Initial beta release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-assertive-1.0.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

flake8_assertive-1.0.0-py2.py3-none-any.whl (5.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flake8-assertive-1.0.0.tar.gz.

File metadata

File hashes

Hashes for flake8-assertive-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7b65e8bdbe1eab101e0e9df78604b39ad89bde24297ca8aa7dd795ec87478c67
MD5 157042618a2c6928d57eb3467233e02a
BLAKE2b-256 405f24bb530168e14f02b707a27e7aea5f5ff5431485876166c83e12dfda30c5

See more details on using hashes here.

Provenance

File details

Details for the file flake8_assertive-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_assertive-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 222d39d2ca6fd58a260fd0f2d8b86db170ec31f6696b320b4d01a7f67682c98d
MD5 8aad5551aa9f676d295f5692017456ae
BLAKE2b-256 785218ae0a63ae2466eaedf6ab4af51612f998afbbd4da93aba9ecee7906f67a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page