{"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":"en","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,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the plugin is installed using `pip install pytest-regex` within the active virtual environment where you run `pytest`.","cause":"The `pytest-regex` plugin is not installed or not accessible to pytest in your current environment.","error":"pytest: error: unrecognized arguments: --regex"},{"fix":"Verify your regex pattern is correct and matches your test node IDs. Use `pytest --collect-only` to inspect the full list of collected test node IDs and refine your regex accordingly. Consider if other filters (`-k`, `-m`) are also contributing to the problem.","cause":"The regular expression provided with `--regex` did not match any of the collected test node IDs, or was too restrictive.","error":"============================= no tests ran in X.YZs ============================="}]}