Cupel v0.5.1
GitHub

Python and pytest#

Cupel's Python adapter is vibernt-cupel in packages/cupel-py. It uses only the Python standard library and requires Python 3.12+ because collection uses sys.monitoring. pytest is supplied by your project and is imported only inside the pytest process. This is core ordinary full guard within the support matrix; current installed evidence is Python 3.14.8 / pytest 9.1.1. The adapter never installs anything or sends data to a network service. Project tests execute normally with their own side effects.

From a Python project root, with packages/cupel-py/src on PYTHONPATH (or the package installed locally):

python3 -m vibernt_cupel collect --root . --runs 2 --out cupel-input.json -- -q
python3 -m vibernt_cupel list --root .
python3 -m vibernt_cupel select 'tests/test_math.py::test_add' --root .
python3 -m vibernt_cupel collect --recheck 'tests/test_math.py::@18' --out checked.json

collect and select write cupel-spec/1 JSON to standard output unless --out is given. list writes a JSON object containing test ids, files, names, units for parametrized rows, and tier tags. Options after -- go to pytest. select resolves Cupel ids, including Class > method, to pytest node ids and runs exactly those rows; it does not accept additional pytest selectors. --recheck accepts one or more unit ids; each unit runs alone in a separate pytest process, replacing the rows' coverage. --runs controls the number of complete suite passes used for durations (default two).

@pytest.mark.cupel_critical, cupel_standard, and cupel_minor map to the corresponding tags; the plugin registers them for --strict-markers. xfail is skipped and strict xpass is failed. A test's setup, call, teardown and function-scoped fixtures belong to coverage.byTest. Imports, collection, and session, module and class fixture setup belong to coverage.setup for the test file. Python subprocess and os.exec* launches of Python executables set spawnsInterpreter.

Sources include repository *.py files outside test directories, virtual environments, dependency directories and dot-directories. conftest.py, test_*.py and *_test.py are excluded. cupel.json scope.include and scope.exclude narrow this set. The Python K1 mapping uses tokenize: every line with a non-whitespace code token is coverable, including string content and uncalled definitions; comments, blank lines and standalone docstrings are excluded. sys.monitoring LINE events are intersected with those lines. This is a line-level Python analogue of K1; Python does not provide the JS collector's nested character ranges. Source hashes are SHA-256 of file bytes.

Shapes use the test definition from the def line through its end, masking string and number tokens before 4-token FNV-1a shingles. Brittleness findings use the S6 strict Python detector plus cupel.json patterns whose language is python (or have no language field).

Cupel CLI detects test_*.py and *_test.py files and can collect Python alongside other detected runners. It runs python3 -m vibernt_cupel collect; python3 must resolve both pytest and the collector. The npm artifact does not bundle the Python package: install the separate local wheel, or expose packages/cupel-py/src on PYTHONPATH for source development. See installation. To choose an explicit interpreter, set a collector command in cupel.json:

{ "runners": { "pytest": { "collector": "/path/to/python -m vibernt_cupel collect" } } }

The JS CLI runs external collectors at the repository root with --root, --runs, --out, and any re-check ids. cupel report, guard, and check also run Python mutation when enabled in cupel.json; report --evidence uses the mutation result's targeted units. It uses the same interpreter and environment as the pytest collector. The resulting input can be validated with cupel validate cupel-input.json.

Run mutation directly with the collected input and a scope file. The scope has critical (boolean), changed (source path to line set), and targeted (unit ids). The command writes the input with mutation: { mutants, targeted, seed, sampled } added:

python3 -m vibernt_cupel mutate --root . --input cupel-input.json --scope scope.json --out mutated-input.json --jobs 2
python3 -m vibernt_cupel confirm --root . --input mutated-input.json --mutation mutated-input.json --ids 'src/math.py:8:10:cmp-flip:12345678' --out confirmed.json

--config cupel.json overrides the default root config. --jobs defaults to half the available cores. Mutants are served through -p vibernt_cupel.mutant in fresh pytest processes; the plugin applies edits in memory and project source files remain unchanged. A failing test counts as a kill only if the collected input listed it as passed. A crash is retried and becomes error; a timeout is checked against a fresh unmutated run. confirm reruns each named survivor twice and writes a mutation object. Edit specs and reports live temporarily under .scratch/.

A mutant's pytest run tries units that caught the same fault in the previous input first, then units in test_<module>.py or <module>_test.py (in any directory), then keeps the collected input order. That order is only an optimization: if a selected test that passed in the input fails in the reordered unmutated baseline, Cupel reruns that fault's baseline and mutant in collected input order; if it still fails there, the existing baseline-failure exclusion applies. It stops early once its new failures come from two different units (rows of one parametrized test count as one unit), because more kills cannot change which unit's kills are unique; when any covering test belongs to a targeted unit, every covering test runs. The scope may carry catchers, mapping mutant ids to earlier catching test ids, and reuse, mapping mutant ids to rows from an earlier run. A reused mutant is not run; its row is copied in place and counts toward maxMutants and the sample exactly as a run mutant would. confirm ignores both ordering history and reuse.

For development measurements only, CUPEL_MUTATION_TIMINGS=1 writes the mutation run's total wall time and the wall time spent establishing unmutated selection baselines to standard error. These measurements are never part of the deterministic result.

Edit this page on GitHub