flake8-pytest-style

2.2.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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')

view raw JSON →