Skip to content

Commit

Permalink
Ignore coverage of a test function skipped mid-way
Browse files Browse the repository at this point in the history
This causes the coverage CI to fail whenever touching this file, so nest
the skipped parts in a `pragma: no cover`.
  • Loading branch information
bluetech committed Dec 5, 2019
1 parent cae1148 commit 8a3c06e
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions testing/test_pytester.py
Expand Up @@ -24,51 +24,51 @@ def test_make_hook_recorder(testdir) -> None:
assert not recorder.getfailures()

pytest.xfail("internal reportrecorder tests need refactoring")

class rep:
excinfo = None
passed = False
failed = True
skipped = False
when = "call"

recorder.hook.pytest_runtest_logreport(report=rep)
failures = recorder.getfailures()
assert failures == [rep]
failures = recorder.getfailures()
assert failures == [rep]

class rep2:
excinfo = None
passed = False
failed = False
skipped = True
when = "call"

rep2.passed = False
rep2.skipped = True
recorder.hook.pytest_runtest_logreport(report=rep2)

modcol = testdir.getmodulecol("")
rep3 = modcol.config.hook.pytest_make_collect_report(collector=modcol)
rep3.passed = False
rep3.failed = True
rep3.skipped = False
recorder.hook.pytest_collectreport(report=rep3)

passed, skipped, failed = recorder.listoutcomes()
assert not passed and skipped and failed

numpassed, numskipped, numfailed = recorder.countoutcomes()
assert numpassed == 0
assert numskipped == 1
assert numfailed == 1
assert len(recorder.getfailedcollections()) == 1

recorder.unregister()
recorder.clear()
recorder.hook.pytest_runtest_logreport(report=rep3)
pytest.raises(ValueError, recorder.getfailures)
if False: # pragma: no cover
class rep:
excinfo = None
passed = False
failed = True
skipped = False
when = "call"

recorder.hook.pytest_runtest_logreport(report=rep)
failures = recorder.getfailures()
assert failures == [rep]
failures = recorder.getfailures()
assert failures == [rep]

class rep2:
excinfo = None
passed = False
failed = False
skipped = True
when = "call"

rep2.passed = False
rep2.skipped = True
recorder.hook.pytest_runtest_logreport(report=rep2)

modcol = testdir.getmodulecol("")
rep3 = modcol.config.hook.pytest_make_collect_report(collector=modcol)
rep3.passed = False
rep3.failed = True
rep3.skipped = False
recorder.hook.pytest_collectreport(report=rep3)

passed, skipped, failed = recorder.listoutcomes()
assert not passed and skipped and failed

numpassed, numskipped, numfailed = recorder.countoutcomes()
assert numpassed == 0
assert numskipped == 1
assert numfailed == 1
assert len(recorder.getfailedcollections()) == 1

recorder.unregister()
recorder.clear()
recorder.hook.pytest_runtest_logreport(report=rep3)
pytest.raises(ValueError, recorder.getfailures)


def test_parseconfig(testdir) -> None:
Expand Down

0 comments on commit 8a3c06e

Please sign in to comment.