Skip to content

Commit 6bb4917

Browse files
authored
Merge pull request #415 from mdboom/coverage-from-subprocesses
Better coverage collection from subprocesses
2 parents 9d6afde + fe3f0f9 commit 6bb4917

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
python -m pip install .[test]
5353
- name: run tests
5454
run: |
55-
python -m pytest tests -n auto -m long_running
55+
python -m pytest tests -m long_running
5656
5757
long_test_windows:
5858
runs-on: windows-latest
@@ -67,5 +67,5 @@ jobs:
6767
python -m pip install .[test]
6868
- name: run tests
6969
run: |
70-
python -m pytest tests -n auto -m long_running
70+
python -m pytest tests -m long_running
7171

bench_runner/scripts/run_benchmarks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,13 @@ def dummy(*args, **kwargs):
459459

460460

461461
if __name__ == "__main__":
462+
# This lets pytest-cov collect coverage data in a subprocess
463+
if "COV_CORE_SOURCE" in os.environ:
464+
try:
465+
from pytest_cov.embed import init
466+
467+
init()
468+
except Exception:
469+
sys.stderr.write("pytest-cov: Failed to setup subprocess coverage.")
470+
462471
main()

bench_runner/scripts/workflow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,13 @@ def main():
391391

392392

393393
if __name__ == "__main__":
394+
# This lets pytest-cov collect coverage data in a subprocess
395+
if "COV_CORE_SOURCE" in os.environ:
396+
try:
397+
from pytest_cov.embed import init
398+
399+
init()
400+
except Exception:
401+
sys.stderr.write("pytest-cov: Failed to setup subprocess coverage.")
402+
394403
main()

bench_runner/templates/workflow_bootstrap.src.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def install_requirements(venv: Path) -> None:
5252
run_in_venv(venv, "pip", ["install", "--upgrade", "pip"])
5353
run_in_venv(venv, "pip", ["install", "-r", "requirements.txt"])
5454

55+
# To facilitate coverage testing
56+
if "--_fast" in sys.argv:
57+
run_in_venv(venv, "pip", ["install", "pytest-cov"])
58+
5559

5660
def main():
5761
venv = Path("venv")

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ test = [
3232
"flake8==7.2.0",
3333
"pyright==1.1.399",
3434
"pytest==8.3.5",
35+
"pytest-cov==6.1.1",
3536
"pytest-xdist==3.6.1",
3637
]
3738

@@ -46,4 +47,11 @@ bench_runner = ["templates/*"]
4647
[tool.pytest.ini_options]
4748
markers = [
4849
"long_running: marks tests as long_running (deselect with '-m \"not running\"')",
50+
]
51+
52+
[tool.coverage.paths]
53+
source = [
54+
"bench_runner",
55+
"/tmp/pytest-of-*/pytest-*/test_whole_workflow*/repo/outer_venv/lib/python*/site-packages/bench_runner",
56+
"/tmp/pytest-of-*/pytest-*/test_whole_workflow*/repo/venv/lib/python*/site-packages/bench_runner",
4957
]

tests/test_workflow.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,7 @@ def test_whole_workflow(tmpdir):
226226
]
227227
)
228228
subprocess.check_call(
229-
[
230-
str(binary),
231-
"-m",
232-
"pip",
233-
"install",
234-
str(bench_runner_checkout),
235-
]
229+
[str(binary), "-m", "pip", "install", f"{bench_runner_checkout}[test]"]
236230
)
237231
subprocess.check_call([str(binary), "-m", "bench_runner", "install"])
238232
# install --check should never fail immediately after install

0 commit comments

Comments
 (0)