diff options
author | Paul Ganssle <pganssle@users.noreply.github.com> | 2018-11-14 10:03:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 10:03:59 -0500 |
commit | 6618dee970ec1e5f92e0f48ec74584caf13075aa (patch) | |
tree | a78236df4cc89173c342ef90c1260d7e1e19d8d4 | |
parent | f201daa40c9bda467ea516658d2c7658e83aadd7 (diff) | |
parent | b3e583920e4b8955ca755393678c369bc5210565 (diff) | |
download | dateutil-6618dee970ec1e5f92e0f48ec74584caf13075aa.tar.gz |
Merge pull request #836 from pganssle/xfail
Skip coverage on xfailed tests
-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] |