pytest-only

raw JSON →
2.1.2 verified Mon Apr 27 auth: no python

Pytest plugin that provides an @pytest.mark.only decorator to run a single test exclusively, ignoring all others. Current version 2.1.2, requires Python >=3.8, <4.0. Compatible with flake8 and pylint plugins to detect lingering only marks.

pip install pytest-only
error AttributeError: module 'pytest' has no attribute 'mark'
cause pytest.mark.only requires the pytest.mark attribute, which may not be available if pytest is not imported correctly or installed.
fix
Install pytest and ensure the test file imports pytest.
error pluggy._manager.PluginValidationError: Plugin 'pytest_only' could not be loaded
cause Outdated setuptools or incorrect plugin discovery.
fix
Upgrade setuptools and reinstall pytest-only.
gotcha Beware of forgetting to remove @pytest.mark.only before committing. Use the flake8 or pylint plugins to catch such occurrences.
fix Run flake8 with the plugin or use a pre-commit hook to detect 'only' marks.
gotcha If multiple tests have @pytest.mark.only, only the first encountered test runs (non-deterministic ordering).
fix Ensure only one test has the @pytest.mark.only decorator at a time.

The @pytest.mark.only decorator causes pytest to skip all other tests and run only the marked test.

import pytest

def test_always():
    assert 1 == 1

@pytest.mark.only
def test_only_this():
    assert 1 == 1

def test_never():
    assert 1 == 2