Registry / testing / flake8-pytest-style

flake8-pytest-style

JSON →
library2.2.0pypypi✓ verified 84d ago

flake8-pytest-style is a flake8 plugin designed to enforce common style guidelines and identify inconsistencies within pytest-based test suites. It helps maintain clean and idiomatic pytest code by reporting a variety of style violations. The current version is 2.2.0, released in October 2025, and it maintains a somewhat regular release cadence, with major/minor updates typically every 3-9 months.

pip install flake8-pytest-style
INSTALL
IMPORT
SIG · FLAKE8-PYTEST-STYL
F
flake8-pytest-style
testingpythonv2.2.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flake8_pytest_style
import flake8_pytest_style
import pytest

Install the plugin, then run `flake8` as you normally would. The plugin automatically integrates with flake8 to check pytest-related style issues in your project.

import os # Create a dummy test file with open('test_example.py', 'w') as f: f.write(""" import pytest @pytest.fixture def my_fixture(scope='function'): # PT001, PT003 return 1 def test_example(my_fixture): # PT004 assert my_fixture == 1 @pytest.mark.parametrize(('val'), [1,2]) # PT023, PT006 def test_parametrized_bad_style(val=10): # PT028 assert val > 0 def test_raises(): with pytest.raises(Exception): pass # PT010, PT011, PT012 """) # Run flake8 with the plugin enabled # flake8 automatically discovers installed plugins print("\n--- Running flake8 ---") os.system("flake8 test_example.py") # Clean up os.remove('test_example.py')
Debug
Known issues
breakingVersion 2.0.0 (released 2024-04-01) inverted the default values for `pytest-fixture-no-parentheses` (PT001) and `pytest-mark-no-parentheses` (PT023). This change aligns with the official pytest style, but may introduce many new violations upon upgrade.
fix
If you experience new PT001 or PT023 violations, you may need to explicitly configure these options in your `flake8` configuration (e.g., `setup.cfg`, `pyproject.toml`) to match your preferred style, or update your code to include/remove parentheses as per the new default.
affects: >=2.0.0
breakingThe minimum Python version requirement has increased across minor and major versions. Version 2.0.0 requires Python >=3.8.1, version 2.1.0 requires Python >=3.9, and version 2.2.0 requires Python >=3.10.
fix
Ensure your project's Python environment meets the minimum version requirement for the `flake8-pytest-style` version you are using. Update your Python environment if necessary.
affects: >=2.0.0
gotchaRules PT004 (fixture without return value should have leading underscore) and PT005 (fixture returning value should not have leading underscore) have been noted by the Ruff linter team (a popular alternative to flake8) as potentially not aligning with all pytest 'best practices'.
fix
While `flake8-pytest-style` still reports these, consider if these specific rules fit your project's conventions. You can selectively ignore them via `flake8` configuration if they conflict with your established patterns or other linter's recommendations.
affects: All
gotchaRule PT028 warns against defining default values for parameters in test functions (e.g., `def test_foo(bar=42):`). Pytest's behavior is to use the default value instead of injecting a fixture if one is defined for that parameter, leading to unexpected test behavior.
fix
Remove default values from test function parameters that are intended to receive fixtures. Fixtures should be injected without an explicit default.
affects: All
Upgrade
Version history
2.2.0latest on PyPI · released Oct 20, 2025
Audit
Dependencies
flake8requiredCore linter that this plugin extends.
pytestrequiredThe testing framework whose style this plugin checks.
Agent activity
68 hits · last 30 days
node
66
Amazon
1
Resources
flake8-pytest-style — pip install flake8-pytest-style · libregistry