CLI tool to assert that each pytest test function contains exactly one assert statement
Project description
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-onlyspecified)1: Findings detected2: 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 does not count:
- Assertions in nested functions or classes
pytest.raisesorpytest.warnscontext managers- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file assert_one_assert_per_pytest-20260104011951.tar.gz.
File metadata
- Download URL: assert_one_assert_per_pytest-20260104011951.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b2f361333e4a3d55980679e292a84d3946b4a913a80ed5498a8384fcf336847
|
|
| MD5 |
f26020ffc1559946029d4ea8b1cfa288
|
|
| BLAKE2b-256 |
090bacc1378c8d966f9444c86f17e034509754b6ba0c6dad37ebf6171689e2ff
|
Provenance
The following attestation bundles were made for assert_one_assert_per_pytest-20260104011951.tar.gz:
Publisher:
release.yml on 10U-Labs-LLC/assert-one-assert-per-pytest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
assert_one_assert_per_pytest-20260104011951.tar.gz -
Subject digest:
8b2f361333e4a3d55980679e292a84d3946b4a913a80ed5498a8384fcf336847 - Sigstore transparency entry: 790018676
- Sigstore integration time:
-
Permalink:
10U-Labs-LLC/assert-one-assert-per-pytest@a9e1fc65fdfd9d5db5be32ef10d59746afe661d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/10U-Labs-LLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a9e1fc65fdfd9d5db5be32ef10d59746afe661d8 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file assert_one_assert_per_pytest-20260104011951-py3-none-any.whl.
File metadata
- Download URL: assert_one_assert_per_pytest-20260104011951-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f33bbeaf209f643552dc012d12ab85a62033222c4c367be9a557b6053d8bb6d4
|
|
| MD5 |
1727e15508294a7abf1419da053f098e
|
|
| BLAKE2b-256 |
23f529ecb7367ea02c30c285cdaea2146d05bf047cb78d7510e2d3640cf6e5f2
|
Provenance
The following attestation bundles were made for assert_one_assert_per_pytest-20260104011951-py3-none-any.whl:
Publisher:
release.yml on 10U-Labs-LLC/assert-one-assert-per-pytest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
assert_one_assert_per_pytest-20260104011951-py3-none-any.whl -
Subject digest:
f33bbeaf209f643552dc012d12ab85a62033222c4c367be9a557b6053d8bb6d4 - Sigstore transparency entry: 790018678
- Sigstore integration time:
-
Permalink:
10U-Labs-LLC/assert-one-assert-per-pytest@a9e1fc65fdfd9d5db5be32ef10d59746afe661d8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/10U-Labs-LLC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a9e1fc65fdfd9d5db5be32ef10d59746afe661d8 -
Trigger Event:
workflow_run
-
Statement type: