A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
Python
242
367 commits
updated Oct 14, 2026
A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
Currently the following errors are reported:
| Code | Description |
|---|---|
| PT001 | use @pytest.fixture over @pytest.fixture() (configurable by pytest-fixture-no-parentheses) |
| PT002 | configuration for fixture '{name}' specified via positional args, use kwargs |
| PT003 | scope='function' is implied in @pytest.fixture() |
| PT004 | fixture '{name}' does not return anything, add leading underscore |
| PT005 | fixture '{name}' returns a value, remove leading underscore |
| PT006 | wrong name(s) type in @pytest.mark.parametrize, expected {expected_type} (configurable by pytest-parametrize-names-type) |
| PT007 | wrong values type in @pytest.mark.parametrize, expected {expected_type} (configurable by pytest-parametrize-values-type and pytest-parametrize-values-row-type) |
| PT008 | use return_value= instead of patching with lambda |
| PT009 | use a regular assert instead of unittest-style '{assertion}' |
| PT010 | set the expected exception in pytest.raises() |
| PT011 | pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception (configurable by pytest-raises-require-match-for) |
| PT012 | pytest.raises() block should contain a single simple statement |
| PT013 | found incorrect import of pytest, use simple 'import pytest' instead |
| PT014 | found duplicate test cases {indexes} in @pytest.mark.parametrize |
| PT015 | assertion always fails, replace with pytest.fail() |
| PT016 | no message passed to pytest.fail() |
| PT017 | found assertion on exception {name} in except block, use pytest.raises() instead |
| PT018 | assertion should be broken down into multiple parts |
| PT019 | fixture {name} without value is injected as parameter, use @pytest.mark.usefixtures instead |
| PT020 | @pytest.yield_fixture is deprecated, use @pytest.fixture |
| PT021 | use yield instead of request.addfinalizer |
| PT022 | no teardown in fixture {name}, use return instead of yield |
| PT023 | use @pytest.mark.foo over @pytest.mark.foo() (configurable by pytest-mark-no-parentheses) |
| PT024 | pytest.mark.asyncio is unnecessary for fixtures |
| PT025 | pytest.mark.usefixtures has no effect on fixtures |
| PT026 | useless pytest.mark.usefixtures without parameters |
| PT027 | use pytest.raises() instead of unittest-style '{assertion}' |
| PT028 | test function {name} has default value for argument {arg}, remove it |
| PT029 | set the expected warning in pytest.warns() |
| PT030 | pytest.warns({warning}) is too broad, set the match parameter or use a more specific warning (configurable by pytest-warns-require-match-for) |
| PT031 | pytest.warns() block should contain a single simple statement |
Install the plugin using the package manager of your choice, e.g.
uv add --group dev flake8-pytest-style
# or
poetry add --group dev flake8-pytest-style
# or
pip install flake8-pytest-style
and then run flake8 as you normally would.
The plugin is a flake8 extension, not a standalone tool. To use it with
pre-commit, add the plugin to the
additional_dependencies section of the official flake8 hook:
repos:
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies:
- flake8-pytest-style==2.2.0
The plugin is configured via flake8 configuration
file and/or CLI options. Specific errors can be selected or ignored;
there are also the following plugin-specific configuration options:
pytest-fixture-no-parentheses — see PT001pytest-parametrize-names-type — see PT006pytest-parametrize-values-type — see PT007pytest-parametrize-values-row-type — see PT007pytest-raises-require-match-for — see PT011pytest-mark-no-parentheses — see PT023pytest-warns-require-match-for — see PT030make init
make format lint test
make bump_major
make bump_minor
make bump_patch
MIT
Unreleased
...
2.2.0 - 2025-10-20
2.1.0 - 2025-01-10
reason= kwarg in pytest.fail for PT016pytest.warns without expected warning)pytest.warns clauses)pytest.warns blocks)2.0.0 - 2024-04-01
pytest-fixture-no-parentheses and pytest-mark-no-parentheses
to conform with pytest official style
1.7.2 - 2023-02-15
pytest.fail1.7.1 - 2023-02-15
1.7.0 - 2023-02-09
assertRaises)1.6.0 - 2021-12-23
py.typed file1.5.1 - 2021-11-05
1.5.0 - 2021-06-18
pytest.mark.usefixtures on fixtures)pytest.mark.usefixtures without parameters)1.4.4 - 2021-06-17
1.4.2 - 2021-05-24
flake8-plugin-utils version to improve stability1.4.1 - 2021-04-01
1.4.0 - 2021-03-14
pytest.mark usage)pytest.mark.asyncio on fixtures)with statements containing a single pass1.3.0 - 2020-08-30
yield fixtures without teardown)1.2.3 - 2020-08-06
flake8-plugin-utils dependency to fix encoding problems on Windows1.2.2 - 2020-07-23
1.2.1 - 2020-06-15
1.2.0 - 2020-06-12
mocker fixtures from pytest-mock for PT008pytest.yield_fixture)request.addfinalizer)1.1.1 - 2020-04-17
match='' as a violation1.1.0 - 2020-04-14
assert False)pytest.fail() without message)except blocks)1.0.0 - 2020-03-26
@pytest.mark.parametrize)0.6.0 - 2020-03-21
pytest-parametrize-names-type for PT006pytest-parametrize-values-type and
pytest-parametrize-values-row-type for PT0070.5.0 - 2020-03-09
pytest-fixture-no-parentheses for PT001from-imports from pytest)0.4.0 - 2020-03-09
with pytest.raises())0.3.1 - 2020-03-09
pytest-raises-require-match-for config option0.3.0 - 2020-03-09
0.2.0 - 2020-03-01
0.1.3 - 2019-05-24
yield fixtures support0.1.2 - 2019-05-23
0.1.1 - 2019-05-23
0.1.0 - 2019-05-23
Overall
Maintained
Code review
Latest release
Releases this year
376 followers · starred Jan 2023
1,674 followers · starred Jul 2025
346 followers · starred Aug 2024
635 followers · starred Mar 2021
A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
Python
242
367 commits
updated Oct 14, 2026
A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
Currently the following errors are reported:
| Code | Description |
|---|---|
| PT001 | use @pytest.fixture over @pytest.fixture() (configurable by pytest-fixture-no-parentheses) |
| PT002 | configuration for fixture '{name}' specified via positional args, use kwargs |
| PT003 | scope='function' is implied in @pytest.fixture() |
| PT004 | fixture '{name}' does not return anything, add leading underscore |
| PT005 | fixture '{name}' returns a value, remove leading underscore |
| PT006 | wrong name(s) type in @pytest.mark.parametrize, expected {expected_type} (configurable by pytest-parametrize-names-type) |
| PT007 | wrong values type in @pytest.mark.parametrize, expected {expected_type} (configurable by pytest-parametrize-values-type and pytest-parametrize-values-row-type) |
| PT008 | use return_value= instead of patching with lambda |
| PT009 | use a regular assert instead of unittest-style '{assertion}' |
| PT010 | set the expected exception in pytest.raises() |
| PT011 | pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception (configurable by pytest-raises-require-match-for) |
| PT012 | pytest.raises() block should contain a single simple statement |
| PT013 | found incorrect import of pytest, use simple 'import pytest' instead |
| PT014 | found duplicate test cases {indexes} in @pytest.mark.parametrize |
| PT015 | assertion always fails, replace with pytest.fail() |
| PT016 | no message passed to pytest.fail() |
| PT017 | found assertion on exception {name} in except block, use pytest.raises() instead |
| PT018 | assertion should be broken down into multiple parts |
| PT019 | fixture {name} without value is injected as parameter, use @pytest.mark.usefixtures instead |
| PT020 | @pytest.yield_fixture is deprecated, use @pytest.fixture |
| PT021 | use yield instead of request.addfinalizer |
| PT022 | no teardown in fixture {name}, use return instead of yield |
| PT023 | use @pytest.mark.foo over @pytest.mark.foo() (configurable by pytest-mark-no-parentheses) |
| PT024 | pytest.mark.asyncio is unnecessary for fixtures |
| PT025 | pytest.mark.usefixtures has no effect on fixtures |
| PT026 | useless pytest.mark.usefixtures without parameters |
| PT027 | use pytest.raises() instead of unittest-style '{assertion}' |
| PT028 | test function {name} has default value for argument {arg}, remove it |
| PT029 | set the expected warning in pytest.warns() |
| PT030 | pytest.warns({warning}) is too broad, set the match parameter or use a more specific warning (configurable by pytest-warns-require-match-for) |
| PT031 | pytest.warns() block should contain a single simple statement |
Install the plugin using the package manager of your choice, e.g.
uv add --group dev flake8-pytest-style
# or
poetry add --group dev flake8-pytest-style
# or
pip install flake8-pytest-style
and then run flake8 as you normally would.
The plugin is a flake8 extension, not a standalone tool. To use it with
pre-commit, add the plugin to the
additional_dependencies section of the official flake8 hook:
repos:
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies:
- flake8-pytest-style==2.2.0
The plugin is configured via flake8 configuration
file and/or CLI options. Specific errors can be selected or ignored;
there are also the following plugin-specific configuration options:
pytest-fixture-no-parentheses — see PT001pytest-parametrize-names-type — see PT006pytest-parametrize-values-type — see PT007pytest-parametrize-values-row-type — see PT007pytest-raises-require-match-for — see PT011pytest-mark-no-parentheses — see PT023pytest-warns-require-match-for — see PT030make init
make format lint test
make bump_major
make bump_minor
make bump_patch
MIT
Unreleased
...
2.2.0 - 2025-10-20
2.1.0 - 2025-01-10
reason= kwarg in pytest.fail for PT016pytest.warns without expected warning)pytest.warns clauses)pytest.warns blocks)2.0.0 - 2024-04-01
pytest-fixture-no-parentheses and pytest-mark-no-parentheses
to conform with pytest official style
1.7.2 - 2023-02-15
pytest.fail1.7.1 - 2023-02-15
1.7.0 - 2023-02-09
assertRaises)1.6.0 - 2021-12-23
py.typed file1.5.1 - 2021-11-05
1.5.0 - 2021-06-18
pytest.mark.usefixtures on fixtures)pytest.mark.usefixtures without parameters)1.4.4 - 2021-06-17
1.4.2 - 2021-05-24
flake8-plugin-utils version to improve stability1.4.1 - 2021-04-01
1.4.0 - 2021-03-14
pytest.mark usage)pytest.mark.asyncio on fixtures)with statements containing a single pass1.3.0 - 2020-08-30
yield fixtures without teardown)1.2.3 - 2020-08-06
flake8-plugin-utils dependency to fix encoding problems on Windows1.2.2 - 2020-07-23
1.2.1 - 2020-06-15
1.2.0 - 2020-06-12
mocker fixtures from pytest-mock for PT008pytest.yield_fixture)request.addfinalizer)1.1.1 - 2020-04-17
match='' as a violation1.1.0 - 2020-04-14
assert False)pytest.fail() without message)except blocks)1.0.0 - 2020-03-26
@pytest.mark.parametrize)0.6.0 - 2020-03-21
pytest-parametrize-names-type for PT006pytest-parametrize-values-type and
pytest-parametrize-values-row-type for PT0070.5.0 - 2020-03-09
pytest-fixture-no-parentheses for PT001from-imports from pytest)0.4.0 - 2020-03-09
with pytest.raises())0.3.1 - 2020-03-09
pytest-raises-require-match-for config option0.3.0 - 2020-03-09
0.2.0 - 2020-03-01
0.1.3 - 2019-05-24
yield fixtures support0.1.2 - 2019-05-23
0.1.1 - 2019-05-23
0.1.0 - 2019-05-23
Overall
Maintained
Code review
Latest release
Releases this year
376 followers · starred Jan 2023
1,674 followers · starred Jul 2025
346 followers · starred Aug 2024
635 followers · starred Mar 2021