Rev 4155: (andrew) Fail tests that subclass bzrlib.tests.TestCase but don't use in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Mar 17 06:11:37 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4155
revision-id: pqm at pqm.ubuntu.com-20090317061133-6do3bjfp3sptf1pu
parent: pqm at pqm.ubuntu.com-20090317023551-f1jm1klbuy1eg4hv
parent: andrew.bennetts at canonical.com-20090317053024-t6nxsi8i5efwpfco
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-03-17 06:11:33 +0000
message:
  (andrew) Fail tests that subclass bzrlib.tests.TestCase but don't use
  	its setUp/tearDown.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
  bzrlib/tests/test_commands.py  test_command.py-20051019190109-3b17be0f52eaa7a8
  bzrlib/tests/test_generate_docs.py test_generate_docs.p-20070102123151-cqctnsrlqwmiljd7-1
  bzrlib/tests/test_http_response.py test_http_response.py-20060628233143-950b2a482a32505d
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
  bzrlib/tests/test_osutils_encodings.py test_osutils_encodin-20061226013130-kkp732tpt3lm91vv-1
  bzrlib/tests/test_pack.py      test_container.py-20070607160755-tr8zc26q18rn0jnb-2
  bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
  bzrlib/tests/test_symbol_versioning.py test_symbol_versioning.py-20060105104851-51d7722c2018d42b
  bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
    ------------------------------------------------------------
    revno: 4153.1.5
    revision-id: andrew.bennetts at canonical.com-20090317053024-t6nxsi8i5efwpfco
    parent: andrew.bennetts at canonical.com-20090317052557-t979dms2wk662967
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: test-run-paranoia
    timestamp: Tue 2009-03-17 16:30:24 +1100
    message:
      Tweak assertions based on Robert's review.
    modified:
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 4153.1.4
    revision-id: andrew.bennetts at canonical.com-20090317052557-t979dms2wk662967
    parent: andrew.bennetts at canonical.com-20090317051526-b32we674o5np5hzm
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: test-run-paranoia
    timestamp: Tue 2009-03-17 16:25:57 +1100
    message:
      Add NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4153.1.3
    revision-id: andrew.bennetts at canonical.com-20090317051526-b32we674o5np5hzm
    parent: andrew.bennetts at canonical.com-20090317030233-u30v9qyztu11cjh5
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: test-run-paranoia
    timestamp: Tue 2009-03-17 16:15:26 +1100
    message:
      Check that bzrlib.tests.TestCase.tearDown is called too.
    modified:
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 4153.1.2
    revision-id: andrew.bennetts at canonical.com-20090317030233-u30v9qyztu11cjh5
    parent: andrew.bennetts at canonical.com-20090317020659-eq1894sj8hziwnsm
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: test-run-paranoia
    timestamp: Tue 2009-03-17 14:02:33 +1100
    message:
      Add missing TestCase.setUp upcalls.
    modified:
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_commands.py  test_command.py-20051019190109-3b17be0f52eaa7a8
      bzrlib/tests/test_generate_docs.py test_generate_docs.p-20070102123151-cqctnsrlqwmiljd7-1
      bzrlib/tests/test_http_response.py test_http_response.py-20060628233143-950b2a482a32505d
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_osutils_encodings.py test_osutils_encodin-20061226013130-kkp732tpt3lm91vv-1
      bzrlib/tests/test_pack.py      test_container.py-20070607160755-tr8zc26q18rn0jnb-2
      bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/tests/test_symbol_versioning.py test_symbol_versioning.py-20060105104851-51d7722c2018d42b
      bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
    ------------------------------------------------------------
    revno: 4153.1.1
    revision-id: andrew.bennetts at canonical.com-20090317020659-eq1894sj8hziwnsm
    parent: pqm at pqm.ubuntu.com-20090317013621-d8sbugz1b1jrmzjk
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: test-run-paranoia
    timestamp: Tue 2009-03-17 13:06:59 +1100
    message:
      Check that TestCase.setUp was called in TestCase.run.  If not, fail the test.
    modified:
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS	2009-03-17 02:35:51 +0000
+++ b/NEWS	2009-03-17 06:11:33 +0000
@@ -87,6 +87,14 @@
     * The ``pb`` argument to ``fetch()`` is deprecated.
       (Martin Pool)
 
+  TESTING:
+
+    * ``bzrlib.tests.TestCase`` now fails the test if its own ``setUp``
+      and ``tearDown`` weren't called.  This catches faulty tests that
+      forget to upcall when overriding ``setUp`` and ``tearDown``.  Those
+      faulty tests were not properly isolated.
+      (Andrew Bennetts, Robert Collins)
+
   INTERNALS:
 
     * New ``assertLength`` method based on one Martin has squirreled away

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-03-16 05:05:52 +0000
+++ b/bzrlib/tests/__init__.py	2009-03-17 05:15:26 +0000
@@ -764,9 +764,12 @@
     def __init__(self, methodName='testMethod'):
         super(TestCase, self).__init__(methodName)
         self._cleanups = []
+        self._bzr_test_setUp_run = False
+        self._bzr_test_tearDown_run = False
 
     def setUp(self):
         unittest.TestCase.setUp(self)
+        self._bzr_test_setUp_run = True
         self._cleanEnvironment()
         self._silenceUI()
         self._startLogFile()
@@ -1326,6 +1329,10 @@
                 try:
                     try:
                         self.setUp()
+                        if not self._bzr_test_setUp_run:
+                            self.fail(
+                                "test setUp did not invoke "
+                                "bzrlib.tests.TestCase's setUp")
                     except KeyboardInterrupt:
                         raise
                     except TestSkipped, e:
@@ -1355,6 +1362,10 @@
 
                     try:
                         self.tearDown()
+                        if not self._bzr_test_tearDown_run:
+                            self.fail(
+                                "test tearDown did not invoke "
+                                "bzrlib.tests.TestCase's tearDown")
                     except KeyboardInterrupt:
                         raise
                     except:
@@ -1379,6 +1390,7 @@
             self.__dict__ = saved_attrs
 
     def tearDown(self):
+        self._bzr_test_tearDown_run = True
         self._runCleanups()
         self._log_contents = ''
         unittest.TestCase.tearDown(self)

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2009-03-12 06:24:39 +0000
+++ b/bzrlib/tests/test_branch.py	2009-03-17 03:02:33 +0000
@@ -471,6 +471,7 @@
     """Tests for _run_with_write_locked_target."""
 
     def setUp(self):
+        TestCase.setUp(self)
         self._calls = []
 
     def func_that_returns_ok(self):

=== modified file 'bzrlib/tests/test_commands.py'
--- a/bzrlib/tests/test_commands.py	2009-02-11 12:49:50 +0000
+++ b/bzrlib/tests/test_commands.py	2009-03-17 03:02:33 +0000
@@ -140,6 +140,7 @@
 class TestRegisterLazy(tests.TestCase):
 
     def setUp(self):
+        tests.TestCase.setUp(self)
         import bzrlib.tests.fake_command
         del sys.modules['bzrlib.tests.fake_command']
         global lazy_command_imported

=== modified file 'bzrlib/tests/test_generate_docs.py'
--- a/bzrlib/tests/test_generate_docs.py	2007-01-18 14:49:08 +0000
+++ b/bzrlib/tests/test_generate_docs.py	2009-03-17 03:02:33 +0000
@@ -33,6 +33,7 @@
 class TestGenerateDocs(TestCase):
 
     def setUp(self):
+        TestCase.setUp(self)
         self.sio = StringIO()
         self.options = Options()
         self.options.bzr_name = 'bzr'

=== modified file 'bzrlib/tests/test_http_response.py'
--- a/bzrlib/tests/test_http_response.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/test_http_response.py	2009-03-17 03:02:33 +0000
@@ -801,6 +801,7 @@
     """
 
     def setUp(self):
+        tests.TestCase.setUp(self)
         # create a test datablock larger than _max_read_size.
         chunk_size = response.RangeFile._max_read_size
         test_pattern = '0123456789ABCDEF'

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2009-03-13 01:10:55 +0000
+++ b/bzrlib/tests/test_osutils.py	2009-03-17 03:02:33 +0000
@@ -376,6 +376,7 @@
 class TestPumpFile(TestCase):
     """Test pumpfile method."""
     def setUp(self):
+        TestCase.setUp(self)
         # create a test datablock
         self.block_size = 512
         pattern = '0123456789ABCDEF'

=== modified file 'bzrlib/tests/test_osutils_encodings.py'
--- a/bzrlib/tests/test_osutils_encodings.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/test_osutils_encodings.py	2009-03-17 03:02:33 +0000
@@ -74,6 +74,7 @@
     """Test the auto-detection of proper terminal encoding."""
 
     def setUp(self):
+        TestCase.setUp(self)
         self._stdout = sys.stdout
         self._stderr = sys.stderr
         self._stdin = sys.stdin
@@ -156,6 +157,7 @@
     """Test detection of default user encoding."""
 
     def setUp(self):
+        TestCase.setUp(self)
         self._stderr = sys.stderr
         self._getpreferredencoding = locale.getpreferredencoding
         self.addCleanup(self._reset)

=== modified file 'bzrlib/tests/test_pack.py'
--- a/bzrlib/tests/test_pack.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/test_pack.py	2009-03-17 03:02:33 +0000
@@ -68,6 +68,7 @@
 class TestContainerWriter(tests.TestCase):
 
     def setUp(self):
+        tests.TestCase.setUp(self)
         self.output = StringIO()
         self.writer = pack.ContainerWriter(self.output.write)
 

=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py	2009-02-23 15:29:35 +0000
+++ b/bzrlib/tests/test_progress.py	2009-03-17 03:02:33 +0000
@@ -58,6 +58,7 @@
 class TestProgress(TestCase):
 
     def setUp(self):
+        TestCase.setUp(self)
         q = DummyProgress()
         self.top = ChildProgress(_stack=FakeStack(q))
 

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2009-03-16 01:56:18 +0000
+++ b/bzrlib/tests/test_selftest.py	2009-03-17 05:30:24 +0000
@@ -1150,6 +1150,7 @@
         class SkippedTest(TestCase):
 
             def setUp(self):
+                TestCase.setUp(self)
                 calls.append('setUp')
                 self.addCleanup(self.cleanup)
 
@@ -1371,6 +1372,30 @@
         self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
             exception.args[0])
 
+    def test_base_setUp_not_called_causes_failure(self):
+        class TestCaseWithBrokenSetUp(TestCase):
+            def setUp(self):
+                pass # does not call TestCase.setUp
+            def test_foo(self):
+                pass
+        test = TestCaseWithBrokenSetUp('test_foo')
+        result = unittest.TestResult()
+        test.run(result)
+        self.assertFalse(result.wasSuccessful())
+        self.assertEqual(1, result.testsRun)
+
+    def test_base_tearDown_not_called_causes_failure(self):
+        class TestCaseWithBrokenTearDown(TestCase):
+            def tearDown(self):
+                pass # does not call TestCase.tearDown
+            def test_foo(self):
+                pass
+        test = TestCaseWithBrokenTearDown('test_foo')
+        result = unittest.TestResult()
+        test.run(result)
+        self.assertFalse(result.wasSuccessful())
+        self.assertEqual(1, result.testsRun)
+
     def test_debug_flags_sanitised(self):
         """The bzrlib debug flags should be sanitised by setUp."""
         if 'allow_debug' in tests.selftest_debug_flags:
@@ -1842,6 +1867,7 @@
 class TestSelftestFiltering(TestCase):
 
     def setUp(self):
+        TestCase.setUp(self)
         self.suite = TestUtil.TestSuite()
         self.loader = TestUtil.TestLoader()
         self.suite.addTest(self.loader.loadTestsFromModuleNames([

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2009-03-11 05:23:57 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2009-03-17 03:02:33 +0000
@@ -2823,6 +2823,7 @@
     """
 
     def setUp(self):
+        tests.TestCase.setUp(self)
         self.writes = []
         self.responder = protocol.ProtocolThreeResponder(self.writes.append)
 

=== modified file 'bzrlib/tests/test_symbol_versioning.py'
--- a/bzrlib/tests/test_symbol_versioning.py	2009-01-17 02:43:24 +0000
+++ b/bzrlib/tests/test_symbol_versioning.py	2009-03-17 03:02:33 +0000
@@ -214,6 +214,7 @@
 class TestSuppressAndActivate(TestCase):
 
     def setUp(self):
+        TestCase.setUp(self)
         existing_filters = list(warnings.filters)
         def restore():
             warnings.filters[:] = existing_filters

=== modified file 'bzrlib/tests/test_xml.py'
--- a/bzrlib/tests/test_xml.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/test_xml.py	2009-03-17 03:02:33 +0000
@@ -509,6 +509,7 @@
     """Whitebox testing of the _encode_and_escape function."""
 
     def setUp(self):
+        TestCase.setUp(self)
         # Keep the cache clear before and after the test
         bzrlib.xml8._ensure_utf8_re()
         bzrlib.xml8._clear_cache()




More information about the bazaar-commits mailing list