{"id":8538,"library":"pytest-regex","title":"pytest-regex","description":"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.","status":"active","version":"0.2.0","language":"python","source_language":"en","source_url":"https://github.com/tylerjereddy/pytest-regex","tags":["pytest","testing","regex","plugin","test-selection"],"install":[{"cmd":"pip install pytest-regex","lang":"bash","label":"Install plugin"}],"dependencies":[{"reason":"This is a pytest plugin and requires pytest to function.","package":"pytest","optional":false}],"imports":[{"note":"Users do not import symbols from `pytest_regex` directly. The plugin integrates with pytest's test collection and selection mechanisms.","symbol":"pytest-regex","correct":"This library is a pytest plugin; its functionality is accessed via the `pytest` command-line interface, not through direct Python imports."}],"quickstart":{"code":"import pytest\n\n# test_example.py\ndef test_add():\n    assert 1 + 1 == 2\n\ndef test_subtract():\n    assert 2 - 1 == 1\n\nclass TestMathOperations:\n    def test_multiply(self):\n        assert 2 * 2 == 4\n\n# To run: save the above as 'test_example.py'\n# Then run from your terminal:\n# pip install pytest pytest-regex\n# pytest --regex \"test_add\"\n# pytest --regex \"TestMathOperations::test_multiply\"\n# pytest --regex \"^(test_add|test_subtract)$\"","lang":"python","description":"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`)."},"warnings":[{"fix":"Ensure your regex pattern accounts for the full test node ID. Use `pytest --collect-only` to see the full node IDs before constructing complex patterns.","message":"The `--regex` flag matches against the *full test node ID*, which includes the file path, module, class, and function name (e.g., `test_module.py::TestClass::test_method`). Simple patterns like `test_my_func` might not match if the full path isn't considered.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `subprocess` to call `pytest` with the desired command-line arguments if programmatic execution with regex filtering is required.","message":"pytest-regex functionality is exclusively exposed via command-line arguments (`--regex` and `--regex-file`). There is no public Python API for direct programmatic interaction with the plugin's regex matching logic.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Start with only the `--regex` filter to confirm your pattern works, then gradually add other filters. If no tests are collected, try removing filters one by one to isolate the issue.","message":"When combining `--regex` with other selection options like `-k` (keyword) or `-m` (marker), pytest typically applies all filters. An overly restrictive combination of filters can lead to 'No tests ran'.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.2.0':46 'allow':12 'beyond':35 'cadenc':53 'capabl':34 'current':43 'execut':18 'express':21,41 'extend':29 'full':24 'id':27 'infrequ':51 'k':37 'keyword':36 'm':40 'maintain':49 'marker':39 'node':26 'plugin':10,57 'pytest':2,5,9,30,54 'pytest-regex':1,4 'regex':3,6,56 'regular':20 'releas':52 'select':15,33,60 'test':16,25,32,55,59 'test-select':58 'use':19 'user':13 'version':44","created_at":"2026-04-16T17:02:43.129601+00:00","updated_at":"2026-04-16T17:02:43.129601+00:00","problems":{"verify_error":"no import statement found"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.2.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://pypi.org/project/pytest-regex/","github":"https://github.com/tylerjereddy/pytest-regex","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pytest-regex/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"skip","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}