Merge lp:~gz/bzr/unexpected_successes_are_bad_654474 into lp:bzr

Proposed by Martin Packman
Status: Merged
Approved by: Andrew Bennetts
Approved revision: no longer in the source branch.
Merged at revision: 5888
Proposed branch: lp:~gz/bzr/unexpected_successes_are_bad_654474
Merge into: lp:bzr
Diff against target: 146 lines (+67/-12)
4 files modified
bzrlib/tests/__init__.py (+26/-0)
bzrlib/tests/per_workingtree/test_smart_add.py (+20/-12)
bzrlib/tests/test_selftest.py (+18/-0)
doc/en/release-notes/bzr-2.4.txt (+3/-0)
To merge this branch: bzr merge lp:~gz/bzr/unexpected_successes_are_bad_654474
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+61147@code.launchpad.net

Commit message

Make test unexpected successes count as failures

Description of the change

Recently a few people have run into a mysterious "FAILED ()" selftest result with no errors reported. This is from using testtools/subunit versions with bug 654474 fixed, and a couple of long-standing unexpected successes in the bzrlib test suite now count as the run failing, but don't give any output.

I did a quick poll about bumping the minimum version of testtools (again), but this branch gets the basics of the handling right without needing that step yet. So, for now they count as and are reported similar to straight failures.

One annoyance is I should really test VerboseTestResult.report_unexpected_success as well, but need to rearrange test_selftest to be a bit more sane and avoid lots of code duplication.

To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

Docstring pedantry:

8 + def addUnexpectedSuccess(self, test, details=None):
9 + """Tell result the test unexpectedly passed, counting as a failure

That sentence should end in a period.

I've chatted IRL about the test_smart_add changes, I think I may have a nicer alternative that; I'll put up a branch in a moment.

Revision history for this message
Andrew Bennetts (spiv) wrote :
Revision history for this message
Andrew Bennetts (spiv) wrote :

The rest of this looks good to me. If you're happy with my tweak then I'm happy for this to land.

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

Tweak seems reasonable to me, I've pulled it into this branch.

Revision history for this message
Martin Packman (gz) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2011-05-16 23:19:29 +0000
+++ bzrlib/tests/__init__.py 2011-05-17 17:06:50 +0000
@@ -449,6 +449,19 @@
449 self.known_failure_count += 1449 self.known_failure_count += 1
450 self.report_known_failure(test, err)450 self.report_known_failure(test, err)
451451
452 def addUnexpectedSuccess(self, test, details=None):
453 """Tell result the test unexpectedly passed, counting as a failure
454
455 When the minimum version of testtools required becomes 0.9.8 this
456 can be updated to use the new handling there.
457 """
458 super(ExtendedTestResult, self).addFailure(test, details=details)
459 self.failure_count += 1
460 self.report_unexpected_success(test,
461 "".join(details["reason"].iter_text()))
462 if self.stop_early:
463 self.stop()
464
452 def addNotSupported(self, test, feature):465 def addNotSupported(self, test, feature):
453 """The test will not be run because of a missing feature.466 """The test will not be run because of a missing feature.
454 """467 """
@@ -613,6 +626,13 @@
613 def report_known_failure(self, test, err):626 def report_known_failure(self, test, err):
614 pass627 pass
615628
629 def report_unexpected_success(self, test, reason):
630 self.stream.write('FAIL: %s\n %s: %s\n' % (
631 self._test_description(test),
632 "Unexpected success. Should have failed",
633 reason,
634 ))
635
616 def report_skip(self, test, reason):636 def report_skip(self, test, reason):
617 pass637 pass
618638
@@ -670,6 +690,12 @@
670 % (self._testTimeString(test),690 % (self._testTimeString(test),
671 self._error_summary(err)))691 self._error_summary(err)))
672692
693 def report_unexpected_success(self, test, reason):
694 self.stream.write(' FAIL %s\n%s: %s\n'
695 % (self._testTimeString(test),
696 "Unexpected success. Should have failed",
697 reason))
698
673 def report_success(self, test):699 def report_success(self, test):
674 self.stream.write(' OK %s\n' % self._testTimeString(test))700 self.stream.write(' OK %s\n' % self._testTimeString(test))
675 for bench_called, stats in getattr(test, '_benchcalls', []):701 for bench_called, stats in getattr(test, '_benchcalls', []):
676702
=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
--- bzrlib/tests/per_workingtree/test_smart_add.py 2011-05-04 21:10:36 +0000
+++ bzrlib/tests/per_workingtree/test_smart_add.py 2011-05-17 17:06:50 +0000
@@ -296,15 +296,25 @@
296 self.wt = self.make_branch_and_tree('.')296 self.wt = self.make_branch_and_tree('.')
297 self.overrideAttr(osutils, 'normalized_filename')297 self.overrideAttr(osutils, 'normalized_filename')
298298
299 def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
300 """Adding unnormalized unicode filenames fail if and only if the
301 workingtree format has the requires_normalized_unicode_filenames flag
302 set.
303 """
304 osutils.normalized_filename = osutils._accessible_normalized_filename
305 if self.workingtree_format.requires_normalized_unicode_filenames:
306 self.assertRaises(
307 errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
308 else:
309 self.wt.smart_add([u'a\u030a'])
310
299 def test_accessible_explicit(self):311 def test_accessible_explicit(self):
300 osutils.normalized_filename = osutils._accessible_normalized_filename312 osutils.normalized_filename = osutils._accessible_normalized_filename
301 if self.workingtree_format.requires_normalized_unicode_filenames:313 if self.workingtree_format.requires_normalized_unicode_filenames:
302 self.expectFailure(314 raise tests.TestNotApplicable(
303 'Working tree format smart_add requires normalized unicode filenames',315 'Working tree format smart_add requires normalized unicode '
304 self.assertRaises, errors.NoSuchFile,316 'filenames')
305 self.wt.smart_add, [u'a\u030a'])317 self.wt.smart_add([u'a\u030a'])
306 else:
307 self.wt.smart_add([u'a\u030a'])
308 self.wt.lock_read()318 self.wt.lock_read()
309 self.addCleanup(self.wt.unlock)319 self.addCleanup(self.wt.unlock)
310 self.assertEqual([('', 'directory'), (u'\xe5', 'file')],320 self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
@@ -314,12 +324,10 @@
314 def test_accessible_implicit(self):324 def test_accessible_implicit(self):
315 osutils.normalized_filename = osutils._accessible_normalized_filename325 osutils.normalized_filename = osutils._accessible_normalized_filename
316 if self.workingtree_format.requires_normalized_unicode_filenames:326 if self.workingtree_format.requires_normalized_unicode_filenames:
317 self.expectFailure(327 raise tests.TestNotApplicable(
318 'Working tree format smart_add requires normalized unicode filenames',328 'Working tree format smart_add requires normalized unicode '
319 self.assertRaises, errors.NoSuchFile,329 'filenames')
320 self.wt.smart_add, [])330 self.wt.smart_add([])
321 else:
322 self.wt.smart_add([])
323 self.wt.lock_read()331 self.wt.lock_read()
324 self.addCleanup(self.wt.unlock)332 self.addCleanup(self.wt.unlock)
325 self.assertEqual([('', 'directory'), (u'\xe5', 'file')],333 self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
326334
=== modified file 'bzrlib/tests/test_selftest.py'
--- bzrlib/tests/test_selftest.py 2011-05-13 12:51:05 +0000
+++ bzrlib/tests/test_selftest.py 2011-05-17 17:06:50 +0000
@@ -1083,6 +1083,24 @@
1083 '\n'1083 '\n'
1084 'OK \\(known_failures=1\\)\n')1084 'OK \\(known_failures=1\\)\n')
10851085
1086 def test_unexpected_success_bad(self):
1087 class Test(tests.TestCase):
1088 def test_truth(self):
1089 self.expectFailure("No absolute truth", self.assertTrue, True)
1090 runner = tests.TextTestRunner(stream=StringIO())
1091 result = self.run_test_runner(runner, Test("test_truth"))
1092 self.assertContainsRe(runner.stream.getvalue(),
1093 "=+\n"
1094 "FAIL: \\S+\.test_truth\n"
1095 "-+\n"
1096 "(?:.*\n)*"
1097 "No absolute truth\n"
1098 "(?:.*\n)*"
1099 "-+\n"
1100 "Ran 1 test in .*\n"
1101 "\n"
1102 "FAILED \\(failures=1\\)\n\\Z")
1103
1086 def test_result_decorator(self):1104 def test_result_decorator(self):
1087 # decorate results1105 # decorate results
1088 calls = []1106 calls = []
10891107
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- doc/en/release-notes/bzr-2.4.txt 2011-05-17 10:30:37 +0000
+++ doc/en/release-notes/bzr-2.4.txt 2011-05-17 17:06:50 +0000
@@ -138,6 +138,9 @@
138 suite. This can include new facilities for writing tests, fixes to 138 suite. This can include new facilities for writing tests, fixes to
139 spurious test failures and changes to the way things should be tested.139 spurious test failures and changes to the way things should be tested.
140140
141* A test that was expected to fail but passes instead now counts as a failure
142 catching up with new testtools and subunit handling. (Martin [GZ], #654474)
143
141* Make it easier for plugins to reuse the per_workingtree scenarios by144* Make it easier for plugins to reuse the per_workingtree scenarios by
142 restoring the wt_scenarios helper that was accidentally deleted.145 restoring the wt_scenarios helper that was accidentally deleted.
143 (Vincent Ladeuil, #783472)146 (Vincent Ladeuil, #783472)