Skip to content

Commit

Permalink
Merge pull request #836 from pganssle/xfail
Browse files Browse the repository at this point in the history
Skip coverage on xfailed tests
  • Loading branch information
pganssle committed Nov 14, 2018
2 parents f201daa + b3e5839 commit 6618dee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/836.misc.rst
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions dateutil/test/conftest.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 6618dee

Please sign in to comment.