#python #marker #cli #pytest

app collect-unmarked-tests

A fast Rust tool to collect Python tests that don't have specific pytest markers

1 unstable release

Uses new Rust 2024

new 0.1.0 Sep 25, 2025

#148 in Testing

Download history 70/week @ 2025-09-19

72 downloads per month

MIT license

17KB
329 lines

Collect unmarked pytest

A fast Rust tool to collect Python tests that don't have specific pytest markers.

Usage

# Scan default 'tests' directory
cargo run

# Scan specific directory
cargo run -- src

# Exclude specific markers
cargo run -- --exclude-markers unit,integration,component,slow tests

Build

Prerequisites:

Debug build:

cargo build
./target/debug/collect-unmarked-tests --help

Release build:

cargo build --release
./target/release/collect-unmarked-tests --help

Install locally (optional):

cargo install --path .
collect-unmarked-tests --help

The last command is equivalent to:

pytest -m 'not unit and not integration and not component and not slow' tests

Default excluded markers

  • unit
  • integration
  • component
  • skip
  • slow

The tool scans Python files for test_* functions and excludes those with pytest markers like @pytest.mark.unit or @skip.

Exit codes

  • 0: No unmarked tests found
  • 1: Unmarked tests found (for CI/CD integration)

Using as a pre-commit hook

Add this to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/stancld/collect-unmarked-tests
    rev: v0.1.0  # Use a specific version tag
    hooks:
      - id: collect-unmarked-tests
        args: ['--exclude-markers', 'unit,integration,component,slow']

To scan only specific directories/packages:

repos:
  - repo: https://github.com/stancld/collect-unmarked-tests
    rev: v0.1.0
    hooks:
      - id: collect-unmarked-tests
        args: ['src/mypackage', 'tests/unit']

Or use a local installation:

repos:
  - repo: local
    hooks:
      - id: collect-unmarked-tests
        name: Check for unmarked pytest tests
        entry: collect-unmarked-tests
        language: system
        files: '\.py$'
        args: ['tests']
        pass_filenames: false

Dependencies

~3–7MB
~125K SLoC