Skip to content

Commit

Permalink
Add code coverage (#4670)
Browse files Browse the repository at this point in the history
* Add automated code coverage

* Add pytest-cov

* Temporarily reduce number of tests

* Run all tests again

* Update .gitignore

* Only run one test

* Specify source instead of input

* Run all tests again

* Trigger CI

* Exclude code coverage reports in test_upload_directory

* Decrease coverage target

* Update .gitignore

* Lint
  • Loading branch information
jrbourbeau committed Oct 1, 2021
1 parent d8c7c6b commit cf018a1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
include =
distributed/*
source =
distributed
omit =
distributed/tests/test*
distributed/hdfs.py
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ jobs:
source continuous_integration/scripts/set_ulimit.sh
pytest distributed -m "not avoid_ci and ${{ matrix.partition }}" --runslow \
--junitxml reports/pytest.xml -o junit_suite_name=$TEST_ID
--junitxml reports/pytest.xml -o junit_suite_name=$TEST_ID --cov=distributed --cov-report=xml
# - name: Debug with tmate on failure
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3

- name: Coverage
uses: codecov/codecov-action@v1

- name: Upload test artifacts
# ensure this runs even if pytest fails
if: >
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ continuous_integration/hdfs-initialized
.DS_Store
.cache
.coverage
.coverage.*
coverage.xml
*.lock
.#*
.eggs/
Expand Down
17 changes: 17 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "85...100"

status:
project:
default:
target: 85%
threshold: 1%
patch: no
changes: no

comment: off
2 changes: 2 additions & 0 deletions continuous_integration/environment-3.7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- bokeh
- click
- cloudpickle
- coverage
- cython # Only tested here; also a dependency of crick
- dask # overridden by git tip below
- filesystem-spec
Expand All @@ -27,6 +28,7 @@ dependencies:
- psutil
- pytest
- pytest-asyncio<0.14.0
- pytest-cov
- pytest-faulthandler
- pytest-repeat
- pytest-rerunfailures
Expand Down
2 changes: 2 additions & 0 deletions continuous_integration/environment-3.8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- bokeh
- click
- cloudpickle
- coverage
- dask # overridden by git tip below
- filesystem-spec
- h5py
Expand All @@ -25,6 +26,7 @@ dependencies:
- psutil
- pytest
- pytest-asyncio<0.14.0
- pytest-cov
- pytest-faulthandler
- pytest-repeat
- pytest-rerunfailures
Expand Down
2 changes: 2 additions & 0 deletions continuous_integration/environment-3.9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- bokeh
- click
- cloudpickle
- coverage
- dask # overridden by git tip below
- filesystem-spec # overridden by git tip below
- h5py
Expand All @@ -28,6 +29,7 @@ dependencies:
- pynvml # Only tested here
- pytest
- pytest-asyncio<0.14.0
- pytest-cov
- pytest-faulthandler
- pytest-repeat
- pytest-rerunfailures
Expand Down
6 changes: 4 additions & 2 deletions distributed/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6861,7 +6861,8 @@ async def test_computation_object_code_client_compute(c, s, a, b):
async def test_upload_directory(c, s, a, b, tmp_path):
from dask.distributed import UploadDirectory

files = set(os.listdir())
# Be sure to exclude code coverage reports
files_start = {f for f in os.listdir() if not f.startswith(".coverage")}

with open(tmp_path / "foo.py", "w") as f:
f.write("x = 123")
Expand All @@ -6887,7 +6888,8 @@ def f():
results = await c.run(f)
assert results[n.worker_address] == 123

assert files == set(os.listdir()) # no change
files_end = {f for f in os.listdir() if not f.startswith(".coverage")}
assert files_start == files_end # no change


@gen_cluster(client=True)
Expand Down

0 comments on commit cf018a1

Please sign in to comment.