skillfed

flake8-pytest-style

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

flake8-pytest-style v2.2.0 201.4K downloads/30d#9,672 on PyPI240
License unclear Active released

What it is and what it does

flake8-pytest-style is a flake8 plugin that integrates directly into your linting workflow to catch style and consistency issues specific to pytest test code. It reports over 30 distinct error codes (PT001–PT031) covering common mistakes like using @pytest.fixture() with unnecessary parentheses, overly broad exception matching in pytest.raises(), unittest-style assertions instead of pytest idioms, and fixture naming/return-value inconsistencies.

The plugin works as a flake8 extension, running automatically when you invoke flake8 on your test files. It is configurable via flake8 settings for several rules (fixture parentheses style, parametrize argument types, exception/warning matching requirements) and requires only one runtime dependency. It supports Python 3.10 through 3.14 and is actively maintained.

Use it for:

  • Enforce consistent pytest fixture style across a team (e.g., @pytest.fixture vs @pytest.fixture()) via PT001/PT023.
  • Catch overly broad exception handlers in pytest.raises() that could mask unrelated errors (PT011).
  • Migrate from unittest-style assertions to pytest idioms automatically during code review (PT009/PT027).
  • Detect fixture naming mistakes and return-value inconsistencies that indicate bugs (PT004/PT005).
  • Validate parametrize decorators for correct argument types and duplicate test cases (PT006/PT007/PT014).
  • Identify deprecated pytest patterns like @pytest.yield_fixture and request.addfinalizer (PT020/PT021).

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A flake8 plugin that detects and reports style inconsistencies and common mistakes in pytest-based test code, enforcing best practices for fixtures, parametrization, assertions, and exception handling.

Yes. If you use pytest and want automated style enforcement for test code, this plugin is worth installing. It has low install friction, active maintenance, no known vulnerabilities, and catches real mistakes that improve test reliability. The only caveat is that the license treatment is marked unclear in the metadata, though the description states MIT—verify the actual license before use in proprietary projects.

Install

flake8-pytest-style on PyPI

pip

pip install flake8-pytest-style

uv

uv add flake8-pytest-style

poetry

poetry add flake8-pytest-style

Installing flake8-pytest-style

Before you install

Low friction installation with a single lightweight runtime dependency (flake8-plugin-utils). Actively maintained with recent releases; last commit 2026-08-13 and version 2.2.0 released 2025-10-20. Requires Python 3.10 or later.

Quickstart

pip install flake8-pytest-style

# Then run flake8 on your test files:
flake8 tests/

# The plugin automatically checks for issues like:
# PT001: @pytest.fixture over @pytest.fixture()
# PT009: regular assert instead of unittest-style assertions

Requires Python 3.10 or later; flake8 must be installed and configured in your project.

Verify before relying

  • Whether the license is actually MIT (description says 'MIT' but meta.license_spdx is null)

Package facts

License not declared (unclear)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — flake8-plugin-utils
Maintenance actively maintained — 298 days since the last release
Last repo commit
First released
Downloads 201,433/month — #9,672 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: flake8_pytest_style-2.2.0-py3-none-any.whl

Keywords: flake8, pytest

Development Status :: 5 - Production/StableEnvironment :: ConsoleEnvironment :: PluginsFramework :: Flake8Framework :: PytestIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: Unit

Tags

flake8 pytest style checkerpytest fixture lintingpytest code qualitytest code style enforcementpytest best practices linterflake8 plugin testingpytest assertion checker
pytest-lintingtest-qualityflake8-plugin

More Testing packages