All Projects → jparise → flake8-assertive

jparise / flake8-assertive

Licence: MIT license
Flake8 unittest assert method checker

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to flake8-assertive

guest3
No description or website provided.
Stars: ✭ 51 (+70%)
Mutual labels:  unittest
HTMLTestRunner cn
HTMLTestRunner 汉化版,同时支持python 2和3,增加截图展示功能,失败重试
Stars: ✭ 191 (+536.67%)
Mutual labels:  unittest
local-data-api
Data API for local, you can write unittest for AWS Aurora Serverless's Data API
Stars: ✭ 99 (+230%)
Mutual labels:  unittest
XUnit.jl
XUnit.jl is a unit-testing framework for Julia.
Stars: ✭ 32 (+6.67%)
Mutual labels:  unittest
jupyterlab-flake8
Jupyterlab python linter for notebooks and text files using flake8
Stars: ✭ 105 (+250%)
Mutual labels:  flake8
CleanArchitecture
Android App Architecture
Stars: ✭ 14 (-53.33%)
Mutual labels:  unittest
VCore
VCore is a Swift collection containing objects, functions, and extensions that I use for my projects
Stars: ✭ 32 (+6.67%)
Mutual labels:  unittest
curso-javascript-testes
Código-fonte do curso "Aprenda a testar Aplicações Javascript"
Stars: ✭ 60 (+100%)
Mutual labels:  unittest
RocketXDelight-Playground
Native Android application built with Kotlin and Jetpack Compose. This project also illustrates the usage of advanced libraries such as Ktor, SqlDelight, Hilt, etc with the recommended practices and Unit Tests.
Stars: ✭ 37 (+23.33%)
Mutual labels:  unittest
xtd
Free open-source modern C++17 / C++20 framework to create console, forms (GUI like WinForms) and unit test applications on Microsoft Windows, Apple macOS and Linux.
Stars: ✭ 321 (+970%)
Mutual labels:  unittest
randunit
Bring unittest to your Android/JVM applications with tiny effort.
Stars: ✭ 33 (+10%)
Mutual labels:  unittest
PizzaDelivery
Pizza Delivery is an open source sample app with robust and professional features. This is a fully realized built entirely in Swift.
Stars: ✭ 20 (-33.33%)
Mutual labels:  unittest
pytest-spark
pytest plugin to run the tests with support of pyspark
Stars: ✭ 65 (+116.67%)
Mutual labels:  unittest
jest-puppe-shots
A Jest plugin for creating screenshots of React components with a little help of Puppeteer
Stars: ✭ 86 (+186.67%)
Mutual labels:  unittest
scuri
Automate Angular unit test and boilerplate with this schematic.
Stars: ✭ 54 (+80%)
Mutual labels:  unittest
TestIt
Generate unit testing boilerplate from kotlin files.
Stars: ✭ 32 (+6.67%)
Mutual labels:  unittest
unitest
🌎 Seamless node and browser unit testing with code coverage
Stars: ✭ 28 (-6.67%)
Mutual labels:  unittest
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-33.33%)
Mutual labels:  unittest
flake8-simplify
❄ A flake8 plugin that helps you to simplify code
Stars: ✭ 97 (+223.33%)
Mutual labels:  flake8
google classroom
Google Classroom Data Pipeline
Stars: ✭ 17 (-43.33%)
Mutual labels:  flake8

Flake8 Unittest Assertion Checker

PyPI Version Python Versions

flake8-assertive is a Flake8 extension that encourages using richer, more specific unittest assertions beyond just the typical assertEqual(a, b) and assertTrue(x) methods. The suggested methods 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
assertTrue(a not in b) assertNotIn(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, round(b, x)) assertAlmostEqual(a, b, x) A501
assertAlmostEqual(a, round(b, x)) assertAlmostEqual(a, b, x) A501
assertNotEqual(a, round(b, x)) assertNotAlmostEqual(a, b, x) A501
assertNotAlmostEqual(a, round(b, x)) assertNotAlmostEqual(a, b, x) 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
assertEquals(a, b) assertEqual(a, b) A503
assertNotEquals(a, b) assertNotEqual(a, b) A503
assertAlmostEquals(a, b, x) assertAlmostEqual(a, b, x) A503
assertNotAlmostEquals(a, b, x) assertNotAlmostEqual(a, b, x) A503
assertTrue(a, b) assertTrue(a, msg=b) A504
assertFalse(a, b) assertFalse(a, msg=b) A504

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
4.0.1 (assertive: 2.1.0, ...) CPython 3.9.10 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}
  • A503: use {func} instead of the deprecated {name}
  • A504: prefer the 'msg=' kwarg for {func} diagnostics

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)

Caveats

There are some specific cases when the suggestion might not match the intent of the original.

Testing the equality operator

assertEqual() won't use the == operator if the comparison has been delegated to a type-specific equalilty function. By default, this is the case for strings, sequences, lists, tuples, sets, and dicts.

If your intent is to specifically test the == operator, consider writing the assertion like this instead:

assertIs(a == b, True)

This approach has the benefit of verifying that the type's __eq__ implementation returns a boolean value. Unfortunately, it also has the downside of reporting the result of a == b on failure instead of the values of a and b.

Suggested by: Serhiy Storchaka

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].