# Which test covers this line? Vitest, Jest and pytest > Find which test covers a line of code: pytest coverage contexts, one coverage run per test in Vitest and Jest, and what related-tests options miss. Web page: https://supercov.com/blog/which-test-covers-this-line · Published 2026-12-05 All Supercov pages for agents: https://supercov.com/llms.txt · Full text: https://supercov.com/llms-full.txt Each way to find the tests that ran a line in Vitest, Jest and pytest, measured on the same project. In pytest, run `pytest --cov --cov-context=test`, then `coverage html --show-contexts`: each line of the report lists the tests that ran it. Vitest and Jest do not record this. Their coverage adds every test into one count per line, so the only built-in way to tell is one coverage run per test. ![A diagram of three tools. Vitest and Jest with --coverage store one count per line, so line 8 shows it ran 2 times without naming tests. coverage.py with --cov-context=test and Supercov store the tests per line, so both name the 2 tests that ran line 8.](https://supercov.com/assets/which-test-covers-this-line-flow-1360.b4f80d40b1.webp) *What one coverage run stores, and whether it can name the tests.* Supercov, which we make, records coverage per test in one normal run of Vitest, Jest, pytest and the other supported runners, and `supercov runs latest line ` lists the tests that ran a line. [See below](#supercov-one-run-any-runner). ## At a glance | Runner | Built in? | How | | --- | --- | --- | | pytest | Yes | `pytest --cov --cov-context=test`, then `coverage html --show-contexts` or `coverage json --show-contexts` | | Vitest | No | One `vitest run --coverage -t ""` per test | | Jest | No | One `jest --coverage -t ""` per test | | Any of them, with Supercov | | `npx supercov -- ` once, then `npx supercov runs latest line ` | We measured each on the same small project: a `discount` function, three tests for it, and one checkout test that calls it. Vitest 5.1.0 with the V8 provider, Jest 30.5.2, and coverage.py 7.17.2 with pytest-cov 7.1.0 and pytest 9.2.0. Every method that names tests gave the same answer: line 6, `return cents - 1000;`, runs in one test, and line 8, `return cents;`, in two. ![A grid of five methods against four tests, HALF, TENOFF at least 10, TENOFF under 10 and checkout. Vitest or Jest --coverage names no tests. vitest related and --findRelatedTests name all four. One coverage run per test names TENOFF under 10 and checkout, in 4 runs. coverage.py --cov-context=test and supercov runs latest line name the same two in 1 run.](https://supercov.com/assets/which-test-covers-this-line-grid-1360.c968ec8ea8.webp) *Which tests each method named for line 8 of discount.js.* ## pytest: coverage contexts ```sh pytest --cov --cov-context=test coverage html --show-contexts coverage json --show-contexts -o contexts.json ``` `--cov-context=test` is pytest-cov's option. It labels everything each test runs with the test's id. With coverage.py alone, set `dynamic_context = test_function` under `[run]`. In the HTML report, click a line to see its tests. The JSON report lists them under each file's `contexts`: ```json "5": ["tests/test_discount.py::test_tenoff_takes_ten_off_orders_of_ten_or_more|run"], "6": ["tests/test_checkout.py::test_checkout_adds_up_the_items|run", "tests/test_discount.py::test_tenoff_does_nothing_under_ten|run"] ``` `|run` means the line ran in the test body. Setup and teardown get their own suffixes. ## Vitest and Jest: one coverage run per test `coverage-final.json` from either runner holds one hit count per statement for the whole run. Line 8 reported 2 hits, with nothing to say which tests made them. To find out, run coverage once per test name and check the line each time: ```sh vitest run --coverage -t "^TENOFF does nothing under ten$" jest --coverage -t "^TENOFF does nothing under ten$" ``` That took four runs for four tests: 1.7 s in Vitest and 1.5 s in Jest, against 0.23 s for one Vitest run of all four. The number of runs grows with the number of tests, so on a real suite this is a script you leave running, not a question you ask. `vitest related src/discount.js` and `jest --findRelatedTests src/discount.js` answer a different question. They follow imports, so both picked all four tests, including two that never reach line 8. ## Supercov: one run, any runner ```sh npx supercov -- npx vitest run npx supercov runs latest line src/discount.js:8 ``` ```text src/discount.js:8 Source 8 | return cents; Status COVERED Evidence: execution only Covering tests TENOFF does nothing under ten [vitest:-1607981173_2] — unit/vitest checkout adds up the items [vitest:2006354534_0] — unit/vitest ``` The same two commands, with `npx jest` or `pytest` in the first, gave the same tests for Jest and pytest. The whole Vitest run under Supercov took 0.89 s. Pass several lines at once, or `--from-file` with one per line, and add `--json` for a script or a coding agent. Each line also lists its branches and conditions with the tests for each. See the [CLI reference](https://supercov.com/docs/cli.md) and [runner support](https://supercov.com/docs/supported-suites.md) for every runner and language, and [Vitest per-test coverage](https://supercov.com/compare/vitest-per-test-coverage.md) for the same question from the test's side.