From f6abf51a4a9179d1f478e176e77b94759a988bbb Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 27 Nov 2020 13:12:49 +0100 Subject: [PATCH] add coverage to tests --- .coveragerc | 12 ++++++++++++ .github/workflows/test.yml | 12 +++++++++++- .gitignore | 4 ++++ codecov.yml | 10 ++++++++++ setup.py | 6 ++++++ test-requirements.txt | 4 ++++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .coveragerc create mode 100644 codecov.yml diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..5ce9c37ed --- /dev/null +++ b/.coveragerc @@ -0,0 +1,12 @@ +[run] +plugins = Cython.Coverage +parallel = True +branch = False +omit = + zmq/eventloop/minitornado/* + zmq/tests/* + +[report] +exclude_lines = + pragma: no cover +ignore_errors = True diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfbb6d673..db80d6e90 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,7 @@ on: env: FORCE_COLOR: "1" + PYZMQ_CYTHON_COVERAGE: "1" jobs: lint: @@ -89,6 +90,12 @@ jobs: python-version: ${{ matrix.python }} architecture: ${{ matrix.arch || 'x64' }} + - name: setup coverage + if: startsWith(matrix.python, 'pypy') + run: | + grep -v plugins .coveragerc > .coveragerc-pypy + mv .coveragerc-pypy .coveragerc + - name: install dependencies run: | pip install --upgrade pip wheel @@ -165,7 +172,10 @@ jobs: - name: run tests run: | - python -m pytest -m "not new_console" -v zmq/tests + python -m pytest --cov zmq -m "not new_console" -v zmq/tests + + - name: upload coverage + run: codecov # FIXME: what's the right incantation to call this? # the same line from appveyor doesn't work here diff --git a/.gitignore b/.gitignore index 385fba2c1..6a03f4e78 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,7 @@ venv *.code-workspace .vscode .mypy_cache +.coverage +htmlcov +coverage.xml +env diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..48274dcdd --- /dev/null +++ b/codecov.yml @@ -0,0 +1,10 @@ +comment: off +# show coverage in CI status, but never consider it a failure +coverage: + status: + project: + default: + target: 0% + patch: + default: + target: 0% diff --git a/setup.py b/setup.py index cd9d2be4e..fe62a6620 100755 --- a/setup.py +++ b/setup.py @@ -413,6 +413,9 @@ def init_settings_from_config(self): if use_static_zmq in ('TRUE', '1'): settings['define_macros'].append(('ZMQ_STATIC', '1')) + if os.environ.get("PYZMQ_CYTHON_COVERAGE"): + settings['define_macros'].append(('CYTHON_TRACE', '1')) + # include internal directories settings.setdefault('include_dirs', []) settings['include_dirs'] += [pjoin('zmq', sub) for sub in ('utils',)] @@ -1326,6 +1329,7 @@ def finalize_options(self): 'include_dirs': ext_include_dirs, } + for submod, packages in submodules.items(): for pkg in sorted(packages): sources = [pjoin("zmq", submod.replace(".", os.path.sep), pkg + suffix)] @@ -1336,6 +1340,8 @@ def finalize_options(self): # set binding so that compiled methods can be inspected # set language-level to 3str, requires Cython 0.29 cython_directives = {"binding": True, "language_level": "3str"} + if os.environ.get("PYZMQ_CYTHON_COVERAGE"): + cython_directives["linetrace"] = True extensions = cythonize(extensions, compiler_directives=cython_directives) if pypy: diff --git a/test-requirements.txt b/test-requirements.txt index ba3d01cfc..1edf42d08 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,10 @@ # gevent wheels on mac cause Illegal Instruction +codecov +# coverage 5 has issues with Cython: https://github.com/cython/cython/issues/3515 +coverage<5 gevent; platform_python_implementation != "PyPy" and sys_platform != "win32" and sys_platform != "darwin" pytest +pytest-cov pytest-rerunfailures tornado mypy; platform_python_implementation != "PyPy"