Rtest: Python test runner built in Rust
Rtest is a high-performance Python test runner built in Rust. It replaces traditional import-heavy test collection with static Abstract Syntax Tree (AST) analysis, significantly speeding up test discovery, especially in large monorepos. Currently in early development (v0.0.x), it aims for `pytest` compatibility while offering performance gains and parallel test execution.
Warnings
- breaking Rtest is in early development (v0.0.x); expect frequent bugs, breaking changes, and evolving features as it progresses towards stability.
- gotcha Path Separator Differences: Rtest uses platform-specific path separators (e.g., `\` on Windows) in test nodeids, unlike `pytest` which normalizes to forward slashes (`/`). This can affect tools or scripts parsing test output.
- gotcha Collection Failures on Complex Codebases: Projects with extensive use of `pytest` plugins, dynamic imports, or metaclass-heavy patterns may fail during rtest collection, even if they work with `pytest`.
- gotcha `--runner native` Limitations: The native test runner is limited to simple test patterns (e.g., `unittest.TestCase`, plain assertions) and currently lacks full support for `pytest` fixtures or `conftest.py`.
- gotcha Limited Parametrized Test Discovery: Rtest only expands parametrized tests during collection when decorator arguments can be statically resolved (e.g., literal values, module-level constants, enum members). Dynamic expressions may not be discovered.
Install
-
pip install rtest
Imports
- rtest command-line tool
rtest [options] [path...]
Quickstart
# my_tests/test_example.py
def test_addition():
assert 1 + 1 == 2
def test_failing_example():
assert 'hello'.upper() == 'HELLO'
# To run these tests from your terminal:
# Navigate to your project root (e.g., one level above my_tests)
# $ pip install rtest
# $ rtest my_tests
# Example with a specific rtest utility:
# from rtest import raises
#
# def test_raises_exception():
# with raises(ValueError, match='invalid literal'):
# int('abc')