Skip to main content

assert-one-assert-per-pytest

Assert that each pytest test function contains exactly one assert.

Why One Assert Per Test?

The "one assert per test" pattern encourages writing focused, atomic tests that verify a single behavior. Benefits include:

  • Clear failure messages: When a test fails, you know exactly what behavior broke
  • Better test names: Tests naturally describe specific behaviors
  • Easier maintenance: Changes to one behavior don't affect unrelated assertions
  • Faster debugging: No need to hunt through multiple assertions

Installation

pip install assert-one-assert-per-pytest

Usage

Command Line

# Scan specific files
assert-one-assert-per-pytest test_example.py

# Scan directories recursively
assert-one-assert-per-pytest tests/

# Use glob patterns
assert-one-assert-per-pytest "tests/**/test_*.py"

# Exclude patterns
assert-one-assert-per-pytest tests/ --exclude "**/conftest.py"

# Verbose output
assert-one-assert-per-pytest tests/ --verbose

# Fail fast (exit on first finding)
assert-one-assert-per-pytest tests/ --fail-fast

# Warn only (always exit 0)
assert-one-assert-per-pytest tests/ --warn-only

GitHub Actions

- uses: 10U-Labs-LLC/assert-one-assert-per-pytest@v1
  with:
    files: "tests/"
    exclude: "**/conftest.py"
    verbose: "true"

As a Python Module

python -m assert_one_assert_per_pytest tests/

Output Format

Default output shows one finding per line:

path/to/test_file.py:10:test_example:0
path/to/test_file.py:25:test_another:3

Format: file_path:line_number:function_name:assert_count

Exit Codes

  • 0: No findings (or --warn-only specified)
  • 1: Findings detected
  • 2: Error (missing files, syntax errors, etc.)

What Counts as an Assert?

This tool counts Python assert statements at the immediate level of test functions. It also counts:

  • pytest.raises() context managers
  • pytest.warns() context managers

It does not count:

  • Assertions in nested functions or classes
  • Helper assertions in fixtures or utility functions

Options

Option Description
--exclude PATTERNS Glob patterns to exclude (comma-separated)
--quiet Suppress all output (exit code only)
--verbose Show detailed processing information
--fail-fast Exit after first finding
--warn-only Always exit 0, even with findings

License

Apache 2.0 - See LICENSE.txt

Metadata

Release files for assert-one-assert-per-pytest 20260830060051

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for assert-one-assert-per-pytest 20260830060051
File Size Uploaded Provenance
assert_one_assert_per_pytest-20260830060051.tar.gz 24.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for assert-one-assert-per-pytest 20260830060051
File Interpreter ABI Platform
assert_one_assert_per_pytest-20260830060051-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / assert_one_assert_per_pytest-20260830060051.tar.gz

Download URL assert_one_assert_per_pytest-20260830060051.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f599fe9c0fca01587bc764460f2e397e4d5501a30631bedb69176d1d76b81d3
BLAKE2b-256 checksum
How to use checksums
3c0aec4e6580ea3d534347f0a35d30be134d05e2f76d0e2786f5718d09ba8e57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / assert_one_assert_per_pytest-20260830060051-py3-none-any.whl

Download URL assert_one_assert_per_pytest-20260830060051-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2877fa127943628b6ea3d8ed6eda451bb4e2ac64177a36231fb3e66040654f45
BLAKE2b-256 checksum
How to use checksums
682f0291e4e72c7b4d8ee4597a9fa8822c0f9823d41c0af971f369a4f4990c5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Security for assert-one-assert-per-pytest 20260830060051

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for assert_one_assert_per_pytest-20260830060051.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page