diff options
| author | Robert Collins <robertc@robertcollins.net> | 2014-11-17 15:42:11 +1300 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2014-11-17 15:42:11 +1300 |
| commit | d30ee53f2eeb9ce4c4a04b7f6e94063edab72611 (patch) | |
| tree | fabc78a989393de15dfe85ade7fffefafc31c1b8 /testtools/tests | |
| parent | f6034dd583c8c4d9f7740cb70ffe6ffd5cab1aee (diff) | |
| download | testtools-d30ee53f2eeb9ce4c4a04b7f6e94063edab72611.tar.gz | |
Fix setUpClass upcalls on Python 2.6.
``testtools.TestCase`` now inherits from unittest2.TestCase, which
provides a ``setUpClass`` for upcalls on Python 2.6.
(Robert Collins, #1393283)
Change-Id: Id56212e3d7d519c7b73d2e19d3e34013fac34544
Diffstat (limited to 'testtools/tests')
| -rw-r--r-- | testtools/tests/test_testcase.py | 47 | ||||
| -rw-r--r-- | testtools/tests/test_testsuite.py | 19 |
2 files changed, 44 insertions, 22 deletions
diff --git a/testtools/tests/test_testcase.py b/testtools/tests/test_testcase.py index eef96ed..185b726 100644 --- a/testtools/tests/test_testcase.py +++ b/testtools/tests/test_testcase.py @@ -1602,40 +1602,43 @@ class TestNullary(TestCase): self.assertRaises(ZeroDivisionError, wrapped) +class Attributes(WithAttributes, TestCase): + @attr('foo') + def simple(self): + pass + + # Not sorted here, forward or backwards. + @attr('foo', 'quux', 'bar') + def many(self): + pass + + # Not sorted here, forward or backwards. + @attr('bar') + @attr('quux') + @attr('foo') + def decorated(self): + pass + + class TestAttributes(TestCase): def test_simple_attr(self): # Adding an attr to a test changes its id(). - class MyTest(WithAttributes, TestCase): - @attr('foo') - def test_bar(self): - pass - case = MyTest('test_bar') - self.assertEqual('testtools.tests.test_testcase.MyTest.test_bar[foo]', + case = Attributes('simple') + self.assertEqual( + 'testtools.tests.test_testcase.Attributes.simple[foo]', case.id()) def test_multiple_attributes(self): - class MyTest(WithAttributes, TestCase): - # Not sorted here, forward or backwards. - @attr('foo', 'quux', 'bar') - def test_bar(self): - pass - case = MyTest('test_bar') + case = Attributes('many') self.assertEqual( - 'testtools.tests.test_testcase.MyTest.test_bar[bar,foo,quux]', + 'testtools.tests.test_testcase.Attributes.many[bar,foo,quux]', case.id()) def test_multiple_attr_decorators(self): - class MyTest(WithAttributes, TestCase): - # Not sorted here, forward or backwards. - @attr('bar') - @attr('quux') - @attr('foo') - def test_bar(self): - pass - case = MyTest('test_bar') + case = Attributes('decorated') self.assertEqual( - 'testtools.tests.test_testcase.MyTest.test_bar[bar,foo,quux]', + 'testtools.tests.test_testcase.Attributes.decorated[bar,foo,quux]', case.id()) diff --git a/testtools/tests/test_testsuite.py b/testtools/tests/test_testsuite.py index 56cbed3..08cd777 100644 --- a/testtools/tests/test_testsuite.py +++ b/testtools/tests/test_testsuite.py @@ -218,6 +218,25 @@ TypeError: run() takes ...1 ...argument...2...given... suite.run(result) self.assertEqual(['addSkip'], [item[0] for item in log]) + def test_setupclass_upcall(self): + # Note that this is kindof-a-case-test, kindof-suite, because + # setUpClass is linked between them. + class Simples(TestCase): + @classmethod + def setUpClass(cls): + super(Simples, cls).setUpClass() + def test_simple(self): + pass + # Test discovery uses the default suite from unittest2 (unless users + # deliberately change things, in which case they keep both pieces). + suite = unittest2.TestSuite([Simples("test_simple")]) + log = [] + result = LoggingResult(log) + suite.run(result) + self.assertEqual( + ['startTest', 'addSuccess', 'stopTest'], + [item[0] for item in log]) + class TestFixtureSuite(TestCase): |
