testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00085
[Merge] lp:~gz/testtools/use_reason_only_on_decorator_fallback_625583 into lp:testtools
Martin [gz] has proposed merging lp:~gz/testtools/use_reason_only_on_decorator_fallback_625583 into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
Related bugs:
#625583 Strange details item reprs on skipped tests in babune
https://bugs.launchpad.net/bugs/625583
This changes the non-testtools-api fallback behaviour of addSkip to only pass on the 'reason' member of the details dict rather than stringifying everything. This makes existing code that starts running on Python 2.7 stick with what was the previous behaviour rather than changing to splurging a bunch of generally superfluous information. People who want or need additional details can switch to using the details parameter rather than the standard reason used by unittest.
It'd be nice to check the normal fallback behaviour in testtools.tests.test_testresult but the way those tests are setup currently makes that a pain, as there's a standard details dict created in the parent class and no way of adding a reason to it, so I just left it at the current for now.
--
https://code.launchpad.net/~gz/testtools/use_reason_only_on_decorator_fallback_625583/+merge/36667
Your team testtools developers is requested to review the proposed merge of lp:~gz/testtools/use_reason_only_on_decorator_fallback_625583 into lp:testtools.
=== modified file 'NEWS'
--- NEWS 2010-09-18 02:10:58 +0000
+++ NEWS 2010-09-26 20:53:39 +0000
@@ -16,6 +16,9 @@
* In normal circumstances, a TestCase will no longer share details with clones
of itself. (Andrew Bennetts, bug #637725)
+* With unittest from Python 2.7 skipped tests will now show only the reason
+ rather than a serialisation of all details. (Martin [gz], #625583)
+
0.9.6
~~~~~
=== modified file 'testtools/testresult/real.py'
--- testtools/testresult/real.py 2010-08-04 14:59:59 +0000
+++ testtools/testresult/real.py 2010-09-26 20:53:39 +0000
@@ -435,8 +435,11 @@
try:
return addSkip(test, details=details)
except TypeError:
- # have to convert
- reason = _details_to_str(details)
+ # extract the reason if it's available
+ try:
+ reason = ''.join(details['reason'].iter_text())
+ except KeyError:
+ reason = 'No reason given'
return addSkip(test, reason)
def addUnexpectedSuccess(self, test, details=None):
=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py 2010-08-04 14:59:32 +0000
+++ testtools/tests/test_testresult.py 2010-09-26 20:53:39 +0000
@@ -536,6 +536,12 @@
getattr(self.converter, outcome)(self, details=details)
self.assertEqual([(outcome, self, err_str)], self.result._events)
+ def check_outcome_details_to_arg(self, outcome, arg):
+ """Call an outcome with a details dict to have an arg extracted."""
+ details, _ = self.get_details_and_string()
+ getattr(self.converter, outcome)(self, details=details)
+ self.assertEqual([(outcome, self, arg)], self.result._events)
+
def check_outcome_exc_info(self, outcome, expected=None):
"""Check that calling a legacy outcome still works."""
# calling some outcome with the legacy exc_info style api (no keyword
@@ -761,7 +767,7 @@
def test_outcome_Extended_py27(self):
self.make_27_result()
- self.check_outcome_details_to_string(self.outcome)
+ self.check_outcome_details_to_arg(self.outcome, 'No reason given')
def test_outcome_Extended_pyextended(self):
self.make_extended_result()
=== modified file 'testtools/tests/test_testtools.py'
--- testtools/tests/test_testtools.py 2010-09-18 02:10:58 +0000
+++ testtools/tests/test_testtools.py 2010-09-26 20:53:39 +0000
@@ -964,8 +964,7 @@
test.run(result)
case = result._events[0][1]
self.assertEqual([('startTest', case),
- ('addSkip', case, "Text attachment: reason\n------------\n"
- "skipping this test\n------------\n"), ('stopTest', case)],
+ ('addSkip', case, "skipping this test"), ('stopTest', case)],
calls)
def test_skipException_in_test_method_calls_result_addSkip(self):
@@ -977,8 +976,7 @@
test.run(result)
case = result._events[0][1]
self.assertEqual([('startTest', case),
- ('addSkip', case, "Text attachment: reason\n------------\n"
- "skipping this test\n------------\n"), ('stopTest', case)],
+ ('addSkip', case, "skipping this test"), ('stopTest', case)],
result._events)
def test_skip__in_setup_with_old_result_object_calls_addSuccess(self):
Follow ups