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

Make ResultReporter respect the failure status set by other plugins; add test for coveragerc from config #405

Merged
merged 2 commits into from
Nov 8, 2018
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
3 changes: 3 additions & 0 deletions nose2/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ class ResultSuccessEvent(Event):
Set this to ``True`` to indicate that the test run was
successful. If no plugin sets the ``success`` to
``True``, the test run fails.
Should be initialized to ``None`` to indicate that the status has not
been set yet (so that plugins can always differentiate an explicit
failure in an earlier hook from no pass/fail status having been set yet.

"""
_attrs = Event._attrs + ('result', 'success')
Expand Down
2 changes: 1 addition & 1 deletion nose2/plugins/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def beforeSummaryReport(self, event):

def wasSuccessful(self, event):
"""Mark full test run as successful or unsuccessful"""
if event.success and self.decided_failure:
if self.decided_failure:
event.success = False

def afterSummaryReport(self, event):
Expand Down
6 changes: 5 additions & 1 deletion nose2/plugins/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ def afterTestRun(self, event):
self._reportSummary(event)

def wasSuccessful(self, event):
event.success = True
# if another plugin did not set it already, start by setting
# success=True
if event.success is None:
event.success = True

for name, events in self.reportCategories.items():
for e in events:
if (e.outcome == result.ERROR or
Expand Down
2 changes: 1 addition & 1 deletion nose2/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def wasSuccessful(self):
try:
return self._success
except AttributeError:
event = events.ResultSuccessEvent(self, False)
event = events.ResultSuccessEvent(self, None)
self.session.hooks.wasSuccessful(event)
self._success = event.success
return self._success
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[report]
show_missing = True
fail_under = 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[coverage]
always-on = True
coverage = part_covered_lib
coverage-config = .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def covered_func():
a = 1
a = a + 8
return a


def uncovered_func():
b = 1
b = b + 8
return b
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import unittest

from part_covered_lib import mod1


class TestLib(unittest.TestCase):
def test1(self):
self.assertEqual(mod1.covered_func(), 9)
13 changes: 13 additions & 0 deletions nose2/tests/functional/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ def test_run_coverage_fail_under(self):
self.assertProcOutputPattern(proc, 'covered_lib', STATS,
total_stats=TOTAL_STATS,
assert_exit_status=1)

def test_run_coverage_fail_under2(self):
"""Check with coverage settings in config, not CLI"""
STATS = '\s+8\s+5\s+38%\s+1, 7-10'
TOTAL_STATS = '\s+8\s+5\s+38%\s'

proc = self.runIn(
'scenario/coverage_config_fail_under2',
'-v'
)
self.assertProcOutputPattern(proc, 'part_covered_lib', STATS,
total_stats=TOTAL_STATS,
assert_exit_status=1)