Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ZeroDivisionError with 0 collected tests #2971

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ def _write_progress_if_past_edge(self):
_PROGRESS_LENGTH = len(' [100%]')

def _get_progress_information_message(self):
progress = self._progress_items_reported * 100 // self._session.testscollected
return ' [{:3d}%]'.format(progress)
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:
Expand Down
1 change: 1 addition & 0 deletions changelog/2971.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``ZeroDivisionError`` when using the ``testmon`` plugin when no tests were actually collected.
18 changes: 18 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,24 @@ def test_foobar(i): pass
""",
)

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([
Expand Down