Skip to main content

Release Notes Downloads GitHub CI Status License: MIT

Run Pytest Tests by Line Number

A pytest plugin that lets you run tests by specifying any line number within the test function or class, not just the exact definition line. This makes it easier to run specific tests from your editor or IDE without needing to navigate to the precise test definition.

The Problem

Pytest natively supports running specific tests using the file.py::test_name syntax, but if you try to use file.py:123 where line 123 is inside a test function (not the exact line where def test_* starts), pytest won't find the test.

This plugin solves that by automatically resolving line numbers to the nearest test function or class.

Installation

uv add pytest-line-runner

Usage

Simply pass a file path and line number to pytest:

pytest tests/test_example.py:42

The plugin will find the test function or class that contains line 42 and run it.

Examples

# tests/test_example.py
def test_addition():
    result = 1 + 1  # Line 3
    assert result == 2  # Line 4

class TestCalculator:  # Line 6
    def test_multiply(self):  # Line 7
        result = 2 * 3  # Line 8
        assert result == 6  # Line 9

All of these commands work:

pytest tests/test_example.py:2   # Runs test_addition (definition line)
pytest tests/test_example.py:3   # Runs test_addition (inside function)
pytest tests/test_example.py:4   # Runs test_addition (inside function)
pytest tests/test_example.py:6   # Runs TestCalculator (class line)
pytest tests/test_example.py:8   # Runs TestCalculator::test_multiply
pytest tests/test_example.py:9   # Runs TestCalculator::test_multiply

Features

  • Works with test functions (both sync and async)
  • Works with test classes
  • Handles decorators correctly (finds tests even when you specify a decorator line)
  • Uses AST parsing for accurate test resolution
  • Automatically falls back to pytest's default behavior if the file doesn't exist or no test is found

License

MIT


This project was created from iloveitaly/python-package-template

Metadata

Release files for pytest-line-runner 0.1.0

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

Source distribution (sdist)

Source distribution for pytest-line-runner 0.1.0
File Size Uploaded Provenance
pytest_line_runner-0.1.0.tar.gz 2.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-line-runner 0.1.0
File Interpreter ABI Platform
pytest_line_runner-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 kB

Release files / pytest_line_runner-0.1.0.tar.gz

Download URL pytest_line_runner-0.1.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4510d4223436b006376e51c2418c452c52ec8f2570556d67f9df5e514d912077
BLAKE2b-256 checksum
How to use checksums
4fa160109a15e73a36a3049c95e57eba32025c7ed76c2160b8c0eb15f1c14ce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pytest_line_runner-0.1.0-py3-none-any.whl

Download URL pytest_line_runner-0.1.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af0ff8c0edae89fda8a542da031949d888eff11b8ff0610a1bdf4133cfc5a087
BLAKE2b-256 checksum
How to use checksums
328a7821b9bb8d00735261c34e2a03156a9c1b152fe8142bed3494611c81d9e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pytest-line-runner 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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