Merge lp:~gmb/zope.testing/argh-argh-argh into lp:~launchpad/zope.testing/3.9.4-fork

Proposed by Graham Binns on 2012-07-05
Status: Merged
Approved by: Graham Binns on 2012-07-05
Approved revision: 52
Merged at revision: 49
Proposed branch: lp:~gmb/zope.testing/argh-argh-argh
Merge into: lp:~launchpad/zope.testing/3.9.4-fork
Diff against target: 109 lines (+34/-9)
3 files modified
setup.py (+1/-1)
src/zope/testing/testrunner/runner.py (+6/-4)
src/zope/testing/testrunner/test_testresult.py (+27/-4)
To merge this branch: bzr merge lp:~gmb/zope.testing/argh-argh-argh
Reviewer Review Type Date Requested Status
Benji York (community) code 2012-07-05 Approve on 2012-07-05
Review via email: mp+113586@code.launchpad.net

Commit message

Update our Python 2.7-compatible code so that it falls back to existing behaviour when run under 2.6. Also bump the patch number to avoid anyone with a stale bad version of p16 in their download-cache from getting knobbled.

Description of the change

This branch tweaks our Python 2.7 compatibility code so that it doesn't break the test suite under Python 2.6.

Previously, we allowed addSkip() to do its thing under Python 2.6. aside from calling up to its parent class. However, existing behaviour is to just call addSuccess() when skipping tests under 2.6, so we decided to preserve that behaviour.

To post a comment you must log in.
Benji York (benji) wrote :

This branch looks good. I think you have a typo, shouldn't "2.6" be "2.7" in the below comment?

    # This test can go away once we're only using Python 2.6

review: Approve (code)
Launchpad QA Bot (lpqabot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2012-06-29 13:43:07 +0000
3+++ setup.py 2012-07-05 14:28:32 +0000
4@@ -85,7 +85,7 @@
5
6 setup(
7 name='zope.testing',
8- version = '3.9.4-p16',
9+ version = '3.9.4-p17',
10 url='http://pypi.python.org/pypi/zope.testing',
11 license='ZPL 2.1',
12 description='Zope testing framework, including the testrunner script.',
13
14=== modified file 'src/zope/testing/testrunner/runner.py'
15--- src/zope/testing/testrunner/runner.py 2012-07-05 12:03:23 +0000
16+++ src/zope/testing/testrunner/runner.py 2012-07-05 14:28:32 +0000
17@@ -795,12 +795,14 @@
18 self._start_time = time.time()
19
20 def addSkip(self, test, reason):
21- if hasattr(unittest.TestResult, 'addSkip'):
22+ if sys.version_info[:-3] < (2, 7):
23 # Python 2.6's unittest.TestResult has no concept of
24- # skipping, so we only call up to the parent class if doing
25- # so won't cause an error.
26+ # skipping, so we fall back to addSuccess() if we're running
27+ # under Python < 2.7.
28+ self.addSuccess(test)
29+ else:
30 unittest.TestResult.addSkip(self, test, reason)
31- self.options.output.test_skip(test, reason)
32+ self.options.output.test_skip(test, reason)
33
34 def addSuccess(self, test):
35 t = max(time.time() - self._start_time, 0.0)
36
37=== modified file 'src/zope/testing/testrunner/test_testresult.py'
38--- src/zope/testing/testrunner/test_testresult.py 2012-07-05 12:03:23 +0000
39+++ src/zope/testing/testrunner/test_testresult.py 2012-07-05 14:28:32 +0000
40@@ -17,6 +17,7 @@
41 __metaclass__ = type
42
43 import sys
44+import time
45 import unittest
46 from StringIO import StringIO
47
48@@ -31,10 +32,14 @@
49
50 def __init__(self):
51 self.test_skip_called = False
52+ self.test_success_called = False
53
54 def test_skip(self, test, reason):
55 self.test_skip_called = True
56
57+ def test_success(self, test, t):
58+ self.test_success_called = True
59+
60
61 class MockOptions:
62
63@@ -81,24 +86,42 @@
64 options, tests=[self.example_suite],
65 layer_name="zope.testing.testrunner.test_testresult.TestLayer")
66
67- def test_addSkip_calls_test_skip_on_output(self):
68+ def test_addSkip_calls_test_skip_on_output_in_python27(self):
69 # TestResult.addSkip() calls the test_skip() method on whatever
70 # it has as an output formatter.
71+ # XXX 2012-07-05 gmb:
72+ # This test is only run under Python 2.7; skips don't exist
73+ # in Python 2.6.
74+ if sys.version_info[:-3] < (2, 7):
75+ return
76 test = self.example_suite._tests[0]
77 self.result.addSkip(test, "Testing")
78 self.assertTrue(self.output.test_skip_called)
79
80- def test_addSkip_appends_skipped_test_to_skipped(self):
81+ def test_addSkip_appends_skipped_test_to_skipped_in_python27(self):
82 # TestResult.addSkip() appends the skipped test to the
83 # TestResult's skipped attribute.
84- # This test is only run under Python 2.7; skips don't exist in
85- # Python 2.6.
86+ # XXX 2012-07-05 gmb:
87+ # This test is only run under Python 2.7; skips don't exist
88+ # in Python 2.6.
89 if sys.version_info[:-3] < (2, 7):
90 return
91 test = self.example_suite._tests[0]
92 self.result.addSkip(test, "Testing")
93 self.assertIn((test, "Testing"), self.result.skipped)
94
95+ # XXX 2012-07-05 gmb:
96+ # This test can go away once we're only using Python 2.7.
97+ def test_addSkip_calls_addSuccess_under_python26(self):
98+ # When running under Python 2.6, addSkip() calls addSuccess(),
99+ # since skips aren't supported under Python 2.6
100+ if sys.version_info[:-3] > (2, 6):
101+ self.skipTest("Test is Python 2.6-specific.")
102+ test = self.example_suite._tests[0]
103+ self.result._start_time = time.time()
104+ self.result.addSkip(test, "Testing")
105+ self.assertTrue(self.output.test_success_called)
106+
107
108 class TestOutputFormatters(unittest.TestCase):
109 """Tests for the handling of test_skip by different output formatters."""

Subscribers

People subscribed via source and target branches