pytest-regex

0.2.0 · active · verified Thu Apr 16

pytest-regex is a pytest plugin that allows users to select tests for execution using regular expressions against the full test node ID. It extends pytest's test selection capabilities beyond keyword (`-k`) and marker (`-m`) expressions. The current version is 0.2.0, and it maintains an infrequent release cadence.

Common errors

Warnings

Install

Imports

Quickstart

Create a `test_example.py` file with some tests. Then, install `pytest` and `pytest-regex`. Run pytest from the command line using the `--regex` flag to filter tests based on a regular expression matching the full test node ID (e.g., `test_example.py::test_add`).

import pytest

# test_example.py
def test_add():
    assert 1 + 1 == 2

def test_subtract():
    assert 2 - 1 == 1

class TestMathOperations:
    def test_multiply(self):
        assert 2 * 2 == 4

# To run: save the above as 'test_example.py'
# Then run from your terminal:
# pip install pytest pytest-regex
# pytest --regex "test_add"
# pytest --regex "TestMathOperations::test_multiply"
# pytest --regex "^(test_add|test_subtract)$"

view raw JSON →