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
1=== modified file 'bzrlib/tests/__init__.py'
2--- bzrlib/tests/__init__.py 2011-05-16 23:19:29 +0000
3+++ bzrlib/tests/__init__.py 2011-05-17 17:06:50 +0000
4@@ -449,6 +449,19 @@
5 self.known_failure_count += 1
6 self.report_known_failure(test, err)
7
8+ def addUnexpectedSuccess(self, test, details=None):
9+ """Tell result the test unexpectedly passed, counting as a failure
10+
11+ When the minimum version of testtools required becomes 0.9.8 this
12+ can be updated to use the new handling there.
13+ """
14+ super(ExtendedTestResult, self).addFailure(test, details=details)
15+ self.failure_count += 1
16+ self.report_unexpected_success(test,
17+ "".join(details["reason"].iter_text()))
18+ if self.stop_early:
19+ self.stop()
20+
21 def addNotSupported(self, test, feature):
22 """The test will not be run because of a missing feature.
23 """
24@@ -613,6 +626,13 @@
25 def report_known_failure(self, test, err):
26 pass
27
28+ def report_unexpected_success(self, test, reason):
29+ self.stream.write('FAIL: %s\n %s: %s\n' % (
30+ self._test_description(test),
31+ "Unexpected success. Should have failed",
32+ reason,
33+ ))
34+
35 def report_skip(self, test, reason):
36 pass
37
38@@ -670,6 +690,12 @@
39 % (self._testTimeString(test),
40 self._error_summary(err)))
41
42+ def report_unexpected_success(self, test, reason):
43+ self.stream.write(' FAIL %s\n%s: %s\n'
44+ % (self._testTimeString(test),
45+ "Unexpected success. Should have failed",
46+ reason))
47+
48 def report_success(self, test):
49 self.stream.write(' OK %s\n' % self._testTimeString(test))
50 for bench_called, stats in getattr(test, '_benchcalls', []):
51
52=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
53--- bzrlib/tests/per_workingtree/test_smart_add.py 2011-05-04 21:10:36 +0000
54+++ bzrlib/tests/per_workingtree/test_smart_add.py 2011-05-17 17:06:50 +0000
55@@ -296,15 +296,25 @@
56 self.wt = self.make_branch_and_tree('.')
57 self.overrideAttr(osutils, 'normalized_filename')
58
59+ def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
60+ """Adding unnormalized unicode filenames fail if and only if the
61+ workingtree format has the requires_normalized_unicode_filenames flag
62+ set.
63+ """
64+ osutils.normalized_filename = osutils._accessible_normalized_filename
65+ if self.workingtree_format.requires_normalized_unicode_filenames:
66+ self.assertRaises(
67+ errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
68+ else:
69+ self.wt.smart_add([u'a\u030a'])
70+
71 def test_accessible_explicit(self):
72 osutils.normalized_filename = osutils._accessible_normalized_filename
73 if self.workingtree_format.requires_normalized_unicode_filenames:
74- self.expectFailure(
75- 'Working tree format smart_add requires normalized unicode filenames',
76- self.assertRaises, errors.NoSuchFile,
77- self.wt.smart_add, [u'a\u030a'])
78- else:
79- self.wt.smart_add([u'a\u030a'])
80+ raise tests.TestNotApplicable(
81+ 'Working tree format smart_add requires normalized unicode '
82+ 'filenames')
83+ self.wt.smart_add([u'a\u030a'])
84 self.wt.lock_read()
85 self.addCleanup(self.wt.unlock)
86 self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
87@@ -314,12 +324,10 @@
88 def test_accessible_implicit(self):
89 osutils.normalized_filename = osutils._accessible_normalized_filename
90 if self.workingtree_format.requires_normalized_unicode_filenames:
91- self.expectFailure(
92- 'Working tree format smart_add requires normalized unicode filenames',
93- self.assertRaises, errors.NoSuchFile,
94- self.wt.smart_add, [])
95- else:
96- self.wt.smart_add([])
97+ raise tests.TestNotApplicable(
98+ 'Working tree format smart_add requires normalized unicode '
99+ 'filenames')
100+ self.wt.smart_add([])
101 self.wt.lock_read()
102 self.addCleanup(self.wt.unlock)
103 self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
104
105=== modified file 'bzrlib/tests/test_selftest.py'
106--- bzrlib/tests/test_selftest.py 2011-05-13 12:51:05 +0000
107+++ bzrlib/tests/test_selftest.py 2011-05-17 17:06:50 +0000
108@@ -1083,6 +1083,24 @@
109 '\n'
110 'OK \\(known_failures=1\\)\n')
111
112+ def test_unexpected_success_bad(self):
113+ class Test(tests.TestCase):
114+ def test_truth(self):
115+ self.expectFailure("No absolute truth", self.assertTrue, True)
116+ runner = tests.TextTestRunner(stream=StringIO())
117+ result = self.run_test_runner(runner, Test("test_truth"))
118+ self.assertContainsRe(runner.stream.getvalue(),
119+ "=+\n"
120+ "FAIL: \\S+\.test_truth\n"
121+ "-+\n"
122+ "(?:.*\n)*"
123+ "No absolute truth\n"
124+ "(?:.*\n)*"
125+ "-+\n"
126+ "Ran 1 test in .*\n"
127+ "\n"
128+ "FAILED \\(failures=1\\)\n\\Z")
129+
130 def test_result_decorator(self):
131 # decorate results
132 calls = []
133
134=== modified file 'doc/en/release-notes/bzr-2.4.txt'
135--- doc/en/release-notes/bzr-2.4.txt 2011-05-17 10:30:37 +0000
136+++ doc/en/release-notes/bzr-2.4.txt 2011-05-17 17:06:50 +0000
137@@ -138,6 +138,9 @@
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.
140
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+
144 * Make it easier for plugins to reuse the per_workingtree scenarios by
145 restoring the wt_scenarios helper that was accidentally deleted.
146 (Vincent Ladeuil, #783472)