Merge lp:~jtv/maas-test/fix-setup-error-reporting into lp:maas-test

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: 17
Merged at revision: 17
Proposed branch: lp:~jtv/maas-test/fix-setup-error-reporting
Merge into: lp:maas-test
Diff against target: 63 lines (+13/-14)
1 file modified
maastest/main.py (+13/-14)
To merge this branch: bzr merge lp:~jtv/maas-test/fix-setup-error-reporting
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+194781@code.launchpad.net

Commit message

Fix breakage when reporting errors during the main script's test setup.

Description of the change

We were using an undocumented trick to show a test's full docstring as part of its description, and it broke when no test was running at the time of the error. There is a documented way: override shortDescription() on the test case.

This won't scale trivially to multiple test cases, but we can cross that bridge when we get to it. A mix-in base class would do it, or a decorator, or just repeating the one-liner with a brief docstring, or patching up the test runner.

(Also, we no longer use the command counter in TestMAAS. That moved into the KVMFixture.)

Jeroen

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'maastest/main.py'
2--- maastest/main.py 2013-11-07 16:05:06 +0000
3+++ maastest/main.py 2013-11-12 04:43:07 +0000
4@@ -14,7 +14,6 @@
5 "main",
6 ]
7
8-import itertools
9 import logging
10 import sys
11 import unittest
12@@ -27,10 +26,6 @@
13
14 class TestMAAS(testtools.TestCase, testresources.ResourcedTestCase):
15
16- def __init__(self, *args, **kwargs):
17- super(TestMAAS, self).__init__(*args, **kwargs)
18- self.command_count = itertools.count(1)
19-
20 @classmethod
21 def setUpClass(cls):
22 # TODO: series and architecture should be script parameters.
23@@ -43,6 +38,18 @@
24 cls.machine.cleanUp()
25 super(TestMAAS, cls).tearDownClass()
26
27+ def shortDescription(self):
28+ """Overridable from `unittest`: Describe the ongoing test.
29+
30+ By default this shows the first line of the test's docstring (if
31+ available), but this `TestCase` is basically our UI so we want full,
32+ user-friendly docstrings.
33+ """
34+ # Cribbed from unittest2.TestCase. The difference is that we return
35+ # the whole docstring, instead of just the first line.
36+ # Future maintainers beware: the docstring may also be None.
37+ return self._testMethodDoc
38+
39 # XXX 2013-11-07 gmb bug=897190:
40 # This exists because of the above bug in testtools, which means
41 # that fixture details don't get included with the TestCase
42@@ -66,13 +73,6 @@
43 self.assertEqual(0, retcode)
44
45
46-class TextTestResult(unittest.runner.TextTestResult):
47- """A TextTestResult which displays the test's docstrings."""
48-
49- def getDescription(self, test):
50- return getattr(test.__class__, test._testMethodName).__doc__
51-
52-
53 def main(args=None):
54 # TODO: control the order in which the tests are run. By default
55 # the tests are run in alphabetical order and we should use the order
56@@ -82,8 +82,7 @@
57 level=logging.DEBUG, stream=output_stream, format="%(message)s")
58 suite = unittest.TestLoader().loadTestsFromTestCase(TestMAAS)
59 runner = unittest.TextTestRunner(
60- stream=output_stream, verbosity=2, descriptions=False,
61- resultclass=TextTestResult)
62+ stream=output_stream, verbosity=2, descriptions=False)
63 runner.run(suite)
64
65

Subscribers

People subscribed via source and target branches