Merge pull request #2971 from blueyed/fix-ZeroDivisionError

Fix ZeroDivisionError with 0 collected tests
This commit is contained in:
Bruno Oliveira 2017-11-30 21:12:46 -02:00 committed by GitHub
commit 369c711f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -313,8 +313,11 @@ class TerminalReporter:
_PROGRESS_LENGTH = len(' [100%]')
def _get_progress_information_message(self):
progress = self._progress_items_reported * 100 // self._session.testscollected
collected = self._session.testscollected
if collected:
progress = self._progress_items_reported * 100 // collected
return ' [{:3d}%]'.format(progress)
return ' [100%]'
def _write_progress_information_filling_space(self):
if not self._show_progress_info:

1
changelog/2971.bugfix Normal file
View File

@ -0,0 +1 @@
Fix ``ZeroDivisionError`` when using the ``testmon`` plugin when no tests were actually collected.

View File

@ -988,6 +988,24 @@ class TestProgress:
""",
)
def test_zero_tests_collected(self, testdir):
"""Some plugins (testmon for example) might issue pytest_runtest_logreport without any tests being
actually collected (#2971)."""
testdir.makeconftest("""
def pytest_collection_modifyitems(items, config):
from _pytest.runner import CollectReport
for node_id in ('nodeid1', 'nodeid2'):
rep = CollectReport(node_id, 'passed', None, None)
rep.when = 'passed'
rep.duration = 0.1
config.hook.pytest_runtest_logreport(report=rep)
""")
output = testdir.runpytest()
assert 'ZeroDivisionError' not in output.stdout.str()
output.stdout.fnmatch_lines([
'=* 2 passed in *=',
])
def test_normal(self, many_tests_file, testdir):
output = testdir.runpytest()
output.stdout.re_match_lines([