pytest-picked
pytest-picked is a pytest plugin (version 0.5.1) that enhances test execution by allowing users to run only the tests related to files changed according to Git. It's currently active and maintained, with releases on PyPI. This helps developers quickly test relevant code without running the entire test suite, particularly useful in continuous integration or local development workflows.
Warnings
- gotcha By default, `pytest-picked` runs tests related to *unstaged* changes (`--mode=unstaged`). To run tests based on changes in a feature branch compared to a parent branch (e.g., `main`), users must explicitly use `--mode=branch` and optionally `--parent-branch`. Misunderstanding this default can lead to unexpected test selection.
- gotcha `pytest-picked` relies on Git status to determine changed files. If Git is not initialized, if there are no detected changes according to Git, or if the repository state is unexpected (e.g., a dirty working tree preventing clear diffs), the plugin might not pick any tests, leading to an empty test run, or fall back to default `pytest` behavior, which can be confusing.
- compatibility As a `pytest` plugin, `pytest-picked`'s functionality is tightly coupled with `pytest` itself. Major upgrades of `pytest` can introduce breaking changes in its internal APIs or collection mechanisms, which might indirectly affect `pytest-picked` and require updates to the plugin to maintain compatibility.
Install
-
pip install pytest-picked
Imports
- pytest-picked plugin
Functionality is exposed via the pytest command-line, e.g., 'pytest --picked'. No direct Python imports are typically used by end-users.
Quickstart
# 1. Install pytest-picked # pip install pytest-picked # 2. Create a test file (e.g., test_example.py) # def test_addition(): # assert 1 + 1 == 2 # # def test_subtraction(): # assert 2 - 1 == 1 # 3. Modify a test file (e.g., add a new test or change an existing one) and do not commit it. # For example, add the following to test_example.py: # def test_multiplication(): # assert 2 * 3 == 6 # 4. Run pytest-picked to execute only the tests related to changed files # Navigate to your project's root directory in the terminal # Assuming test_example.py has unstaged changes: # pytest --picked # Example to run tests from modified files first, then all others: # pytest --picked=first # Example to run tests based on changes in the current branch compared to 'main': # pytest --picked --mode=branch --parent-branch=main