Home

Awesome

flake8-pytest-style

pypi Python: 3.8+ Downloads Build Status Code coverage License: MIT Code style: black

Description

A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.

Currently the following errors are reported:

CodeDescription
PT001use @pytest.fixture over @pytest.fixture() <br> (configurable by pytest-fixture-no-parentheses)
PT002configuration for fixture '{name}' specified via positional args, use kwargs
PT003scope='function' is implied in @pytest.fixture()
PT004fixture '{name}' does not return anything, add leading underscore
PT005fixture '{name}' returns a value, remove leading underscore
PT006wrong name(s) type in @pytest.mark.parametrize, expected {expected_type} <br> (configurable by pytest-parametrize-names-type)
PT007wrong values type in @pytest.mark.parametrize, expected {expected_type} <br> (configurable by pytest-parametrize-values-type and pytest-parametrize-values-row-type)
PT008use return_value= instead of patching with lambda
PT009use a regular assert instead of unittest-style '{assertion}'
PT010set the expected exception in pytest.raises()
PT011pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception <br> (configurable by pytest-raises-require-match-for)
PT012pytest.raises() block should contain a single simple statement
PT013found incorrect import of pytest, use simple 'import pytest' instead
PT014found duplicate test cases {indexes} in @pytest.mark.parametrize
PT015assertion always fails, replace with pytest.fail()
PT016no message passed to pytest.fail()
PT017found assertion on exception {name} in except block, use pytest.raises() instead
PT018assertion should be broken down into multiple parts
PT019fixture {name} without value is injected as parameter, use @pytest.mark.usefixtures instead
PT020@pytest.yield_fixture is deprecated, use @pytest.fixture
PT021use yield instead of request.addfinalizer
PT022no teardown in fixture {name}, use return instead of yield
PT023use @pytest.mark.foo over @pytest.mark.foo() <br> (configurable by pytest-mark-no-parentheses)
PT024pytest.mark.asyncio is unnecessary for fixtures
PT025pytest.mark.usefixtures has no effect on fixtures
PT026useless pytest.mark.usefixtures without parameters
PT027use pytest.raises() instead of unittest-style '{assertion}'

Installation

pip install flake8-pytest-style

Configuration

The plugin has the following configuration options:

For developers

Install deps and setup pre-commit hook

make init

Run linters, autoformat, tests etc.

make format lint test

Bump new version

make bump_major
make bump_minor
make bump_patch

License

MIT

Change Log

Unreleased

...

2.0.0 - 2024-04-01

1.7.2 - 2023-02-15

1.7.1 - 2023-02-15

1.7.0 - 2023-02-09

1.6.0 - 2021-12-23

1.5.1 - 2021-11-05

1.5.0 - 2021-06-18

1.4.4 - 2021-06-17

1.4.2 - 2021-05-24

1.4.1 - 2021-04-01

1.4.0 - 2021-03-14

1.3.0 - 2020-08-30

1.2.3 - 2020-08-06

1.2.2 - 2020-07-23

1.2.1 - 2020-06-15

1.2.0 - 2020-06-12

1.1.1 - 2020-04-17

1.1.0 - 2020-04-14

1.0.0 - 2020-03-26

0.6.0 - 2020-03-21

0.5.0 - 2020-03-09

0.4.0 - 2020-03-09

0.3.1 - 2020-03-09

0.3.0 - 2020-03-09

0.2.0 - 2020-03-01

0.1.3 - 2019-05-24

0.1.2 - 2019-05-23

0.1.1 - 2019-05-23

0.1.0 - 2019-05-23