Skip to content

Commit 39f3b20

Browse files
committed
Generate code coverage report
Signed-off-by: Keith Battocchi <[email protected]>
1 parent 5c6d87b commit 39f3b20

File tree

4 files changed

+75
-8
lines changed

4 files changed

+75
-8
lines changed

.github/workflows/ci.yml

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ jobs:
9797
runs-on: ubuntu-latest
9898
strategy:
9999
matrix:
100-
kind: [except customer scenarios, customer scenarios]
100+
kind: [except-customer-scenarios, customer-scenarios]
101101
include:
102-
- kind: "except customer scenarios"
102+
- kind: "except-customer-scenarios"
103103
extras: "[tf,plt]"
104104
pattern: "(?!CustomerScenarios)"
105105
install_graphviz: true
106106
version: 3.8 # no supported version of tensorflow for 3.9
107-
- kind: "customer scenarios"
107+
- kind: "customer-scenarios"
108108
extras: "[plt,dowhy]"
109109
pattern: "CustomerScenarios"
110110
version: 3.9
@@ -127,16 +127,28 @@ jobs:
127127
# Add verbose flag to pip installation if in debug mode
128128
- run: pip install -e .${{ matrix.extras }} ${{ fromJSON('["","-v"]')[runner.debug] }}
129129
name: Install econml
130-
- run: pip install pytest pytest-runner jupyter jupyter-client nbconvert nbformat seaborn xgboost tqdm
130+
- run: pip install pytest pytest-runner coverage jupyter jupyter-client nbconvert nbformat seaborn xgboost tqdm
131131
name: Install test and notebook requirements
132132
- run: pip list
133133
name: List installed packages
134134
- run: python setup.py pytest
135135
name: Run notebook tests
136+
id: run_tests
136137
env:
137138
PYTEST_ADDOPTS: '-m "notebook"'
138139
NOTEBOOK_DIR_PATTERN: ${{ matrix.pattern }}
139-
140+
COVERAGE_PROCESS_START: 'setup.cfg'
141+
- run: mv .coverage .coverage.${{ matrix.kind }}
142+
# Run whether or not the tests passed, but only if they ran at all
143+
if: success() || failure() && contains(fromJSON('["success", "failure"]'), steps.run_tests.outcome)
144+
name: Make coverage filename unique
145+
- uses: actions/upload-artifact@v3
146+
name: Upload coverage report
147+
if: success() || failure() && contains(fromJSON('["success", "failure"]'), steps.run_tests.outcome)
148+
with:
149+
name: coverage
150+
path: .coverage.${{ matrix.kind }}
151+
140152
tests:
141153
name: "Run tests"
142154
needs: [eval]
@@ -191,10 +203,53 @@ jobs:
191203
name: Install pytest
192204
- run: python setup.py pytest
193205
name: Run tests
206+
id: run_tests
194207
env:
195208
PYTEST_ADDOPTS: ${{ matrix.opts }}
196209
COVERAGE_PROCESS_START: 'setup.cfg'
197-
# todo: publish test results, coverage info
210+
- run: mv .coverage .coverage.${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.kind }}
211+
# Run whether or not the tests passed, but only if they ran at all
212+
if: success() || failure() && contains(fromJSON('["success", "failure"]'), steps.run_tests.outcome)
213+
name: Make coverage filename unique
214+
- uses: actions/upload-artifact@v3
215+
name: Upload coverage report
216+
if: success() || failure() && contains(fromJSON('["success", "failure"]'), steps.run_tests.outcome)
217+
with:
218+
name: coverage
219+
path: .coverage.${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.kind }}
220+
221+
coverage-report:
222+
name: "Coverage report"
223+
needs: [tests, notebooks]
224+
if: success() || failure()
225+
runs-on: ubuntu-latest
226+
steps:
227+
- uses: actions/checkout@v3
228+
name: Checkout repository
229+
with:
230+
ref: ${{ env.ref }}
231+
- uses: actions/download-artifact@v3
232+
name: Get coverage reports
233+
with:
234+
name: coverage
235+
path: coverage
236+
- uses: actions/setup-python@v4
237+
name: Setup Python
238+
with:
239+
python-version: 3.8
240+
- run: pip install coverage
241+
name: Install coverage
242+
- run: coverage combine coverage/
243+
name: Combine coverage reports
244+
- run: coverage report -m --format=markdown > $GITHUB_STEP_SUMMARY
245+
name: Generate coverage report
246+
- run: coverage html
247+
name: Generate coverage html --fail-under=86
248+
- uses: actions/upload-artifact@v3
249+
name: Upload coverage report
250+
with:
251+
name: coverage
252+
path: htmlcov
198253

199254
build:
200255
name: Build package

econml/tests/test_notebooks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88

99
_nbdir = os.path.join(os.path.dirname(__file__), '..', '..', 'notebooks')
10+
_maindir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..'))
1011

1112
_nbsubdirs = ['.', 'CustomerScenarios', 'Solutions'] # TODO: add AutoML notebooks
1213

@@ -28,6 +29,15 @@ def test_notebook(file):
2829
import nbconvert
2930

3031
nb = nbformat.read(os.path.join(_nbdir, file), as_version=4)
32+
33+
# make sure that coverage outputs reflect notebook contents
34+
nb.cells.insert(0, nbformat.v4.new_code_cell(f"""
35+
import os, coverage
36+
cwd = os.getcwd()
37+
os.chdir({_maindir!r}) # change to the root directory, so that setup.cfg is found
38+
coverage.process_startup()
39+
os.chdir(cwd) # change back to the original directory"""))
40+
3141
# require all cells to complete within 15 minutes, which will help prevent us from
3242
# creating notebooks that are annoying for our users to actually run themselves
3343
ep = nbconvert.preprocessors.ExecutePreprocessor(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ requires = [
99
build-backend = "setuptools.build_meta"
1010

1111
[tool.pytest.ini_options]
12-
addopts = "--junitxml=junit/test-results.xml -n auto --strict-markers --cov-config=setup.cfg --cov=econml --cov-report=xml"
12+
addopts = "--junitxml=junit/test-results.xml -n auto --strict-markers --cov-config=setup.cfg --cov=econml"
1313
markers = [
1414
"slow",
1515
"notebook",

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ exclude =
9292

9393
; coverage configuration
9494
[coverage:run]
95-
omit = econml/tests/*
9695
branch = True
9796
; need to explicitly add support for multiprocessing for OrthoForest
9897
concurrency =
9998
thread
10099
multiprocessing
100+
source = econml
101+
omit = econml/tests/*
102+
relative_files = True

0 commit comments

Comments
 (0)