diff options
author | Paul Ganssle <paul@ganssle.io> | 2018-11-10 12:20:11 -0500 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2018-11-13 19:42:19 -0500 |
commit | b3e583920e4b8955ca755393678c369bc5210565 (patch) | |
tree | a78236df4cc89173c342ef90c1260d7e1e19d8d4 | |
parent | f201daa40c9bda467ea516658d2c7658e83aadd7 (diff) | |
download | dateutil-b3e583920e4b8955ca755393678c369bc5210565.tar.gz |
Skip coverage on xfailed tests
This automatically attaches the `no_cover` marker to anything marked
`xfail` *if* the `xfail` condition is met. This allows us to do the test
coverage in one run instead of two.
-rw-r--r-- | changelog.d/836.misc.rst | 1 | ||||
-rw-r--r-- | dateutil/test/conftest.py | 17 | ||||
-rw-r--r-- | tox.ini | 3 |
3 files changed, 19 insertions, 2 deletions
diff --git a/changelog.d/836.misc.rst b/changelog.d/836.misc.rst new file mode 100644 index 0000000..50b22a0 --- /dev/null +++ b/changelog.d/836.misc.rst @@ -0,0 +1 @@ +Fixed test coverage communication so that only one ``pytest`` invocation is necessary to avoid ``xfail`` tests contributing to the code coverage. (gh pr #836) diff --git a/dateutil/test/conftest.py b/dateutil/test/conftest.py index 4e12059..3876b4d 100644 --- a/dateutil/test/conftest.py +++ b/dateutil/test/conftest.py @@ -1,4 +1,21 @@ import os +import pytest + + +# Configure pytest to ignore xfailing tests +# See: https://stackoverflow.com/a/53198349/467366 +def pytest_collection_modifyitems(items): + for item in items: + # Python 3.3 support + marker_getter = getattr(item, 'get_closest_marker', + getattr(item, 'get_marker')) + + marker = marker_getter('xfail') + + # Need to query the args because conditional xfail tests still have + # the xfail mark even if they are not expected to fail + if marker and (not marker.args or marker.args[0]): + item.add_marker(pytest.mark.no_cover) def set_tzpath(): @@ -16,8 +16,7 @@ skip_missing_interpreters = true description = run the unit tests with pytest under {basepython} setenv = COVERAGE_FILE={toxworkdir}/.coverage.{envname} passenv = DATEUTIL_MAY_CHANGE_TZ TOXENV CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* CODECOV_* -commands = python -m pytest -m "not xfail" {posargs: "{toxinidir}/dateutil/test" --cov-config="{toxinidir}/tox.ini" --cov=dateutil} - python -m pytest -m "xfail" {posargs: "{toxinidir}/dateutil/test"} +commands = python -m pytest {posargs: "{toxinidir}/dateutil/test" --cov-config="{toxinidir}/tox.ini" --cov=dateutil} deps = -rrequirements-dev.txt [testenv:coverage] |