Skip to content

Commit 5422cdf

Browse files
coverage args as env var
1 parent 04f1828 commit 5422cdf

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.github/workflows/test-python.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ jobs:
111111
env:
112112
GEOENGINE_TEST_CODE_PATH: ${{ github.workspace }}/backend
113113
GEOENGINE_TEST_BUILD_TYPE: "release"
114+
COVERAGE_COMMAND: ${{ steps.vars.outputs.COVERAGE_COMMAND }}
114115
- name: Report coverage to Coveralls
115116
if: ${{ inputs.coverage }}
116117
# 1. We need to adjust the paths in the lcov file to match the repository structure.

test_all_notebooks.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import subprocess
88
import sys
99

10+
COVERAGE_COMMAND_ENV_VAR = "COVERAGE_COMMAND"
11+
1012

1113
def eprint(*args, **kwargs):
1214
"""Print to stderr."""
1315
print(*args, file=sys.stderr, **kwargs)
1416

1517

16-
def run_test_notebook(notebook_path) -> bool:
18+
def run_test_notebook(notebook_path: str, coverage_args: list[str]) -> bool:
1719
"""Run test_notebook.py for the given notebook."""
1820

1921
pytest_bin = shutil.which("pytest")
@@ -22,7 +24,7 @@ def run_test_notebook(notebook_path) -> bool:
2224
raise RuntimeError("Python 3 not found")
2325

2426
result = subprocess.run(
25-
[pytest_bin, "--ignore=test", "--cov", "--cov-append", "test_notebook.py"],
27+
[pytest_bin, "--ignore=test", *coverage_args, "test_notebook.py"],
2628
env={
2729
**os.environ,
2830
"INPUT_FILE": notebook_path,
@@ -40,6 +42,14 @@ def run_test_notebook(notebook_path) -> bool:
4042
return False
4143

4244

45+
def parse_coverage_command() -> list[str]:
46+
"""Get coverage command from environment variable."""
47+
coverage_cmd = os.getenv(COVERAGE_COMMAND_ENV_VAR)
48+
if not coverage_cmd:
49+
return []
50+
return [*coverage_cmd.split(), "--cov-append"]
51+
52+
4353
def main() -> int:
4454
"""Run all Jupyter Notebooks and check for errors."""
4555

@@ -49,13 +59,19 @@ def main() -> int:
4959
eprint(f"The folder {example_folder} does not exist.")
5060
return -1
5161

62+
coverage_args = parse_coverage_command()
63+
if coverage_args:
64+
eprint(f"Using coverage args: {' '.join(coverage_args)}")
65+
else:
66+
eprint(f"No coverage args in env {COVERAGE_COMMAND_ENV_VAR} provided.")
67+
5268
for root, _dirs, files in os.walk(example_folder):
5369
for file in files:
5470
if not file.endswith(".ipynb"):
5571
eprint(f"Skipping non-notebook file {file}")
5672
continue
5773
notebook_path = os.path.join(root, file)
58-
if not run_test_notebook(notebook_path):
74+
if not run_test_notebook(notebook_path, coverage_args):
5975
return -1
6076

6177
break # skip subdirectories

0 commit comments

Comments
 (0)