Rev 5582: Get rid of _captureVar and _old_env in TestCase. in file:///home/vila/src/bzr/bugs/test-isolation/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Dec 21 09:33:32 GMT 2010


At file:///home/vila/src/bzr/bugs/test-isolation/

------------------------------------------------------------
revno: 5582
revision-id: v.ladeuil+lp at free.fr-20101221093332-g1t5wi6ssb2squcx
parent: v.ladeuil+lp at free.fr-20101221092126-lltuzt8p6cb1qdzo
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: final-cleanup
timestamp: Tue 2010-12-21 10:33:32 +0100
message:
  Get rid of _captureVar and _old_env in TestCase.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-12-21 09:21:26 +0000
+++ b/bzrlib/tests/__init__.py	2010-12-21 09:33:32 +0000
@@ -933,7 +933,6 @@
         self.addDetail("log", content.Content(content.ContentType("text",
             "plain", {"charset": "utf8"}),
             lambda:[self._get_log(keep_log_file=True)]))
-        self._old_env = {}
         self._cleanEnvironment()
         self._silenceUI()
         self._startLogFile()
@@ -1639,10 +1638,6 @@
         for name, value in isolated_environ.iteritems():
             self.overrideEnv(name, value)
 
-    def _captureVar(self, name, newvalue):
-        """Set an environment variable, and reset it when finished."""
-        self._old_env[name] = osutils.set_or_unset_env(name, newvalue)
-
     def _restoreHooks(self):
         for klass, (name, hooks) in self._preserved_hooks.items():
             setattr(klass, name, hooks)

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2010-12-18 19:00:12 +0000
+++ b/bzrlib/tests/test_selftest.py	2010-12-21 09:33:32 +0000
@@ -3415,28 +3415,6 @@
 
 class TestEnvironHandling(tests.TestCase):
 
-    def test__captureVar_None_called_twice_leaks(self):
-        self.failIf('MYVAR' in os.environ)
-        self._captureVar('MYVAR', '42')
-        # We need an embedded test to observe the bug
-        class Test(tests.TestCase):
-            def test_me(self):
-                # The first call save the 42 value
-                self._captureVar('MYVAR', None)
-                self.assertEquals(None, os.environ.get('MYVAR'))
-                self.assertEquals('42', self._old_env.get('MYVAR'))
-                # But the second one erases it !
-                self._captureVar('MYVAR', None)
-                self.assertEquals(None, self._old_env.get('MYVAR'))
-        output = StringIO()
-        result = tests.TextTestResult(output, 0, 1)
-        Test('test_me').run(result)
-        if not result.wasStrictlySuccessful():
-            self.fail(output.getvalue())
-        # And we have lost all trace of the original value
-        self.assertEquals(None, os.environ.get('MYVAR'))
-        self.assertEquals(None, self._old_env.get('MYVAR'))
-
     def test_overrideEnv_None_called_twice_doesnt_leak(self):
         self.failIf('MYVAR' in os.environ)
         self.overrideEnv('MYVAR', '42')

=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt	2010-12-20 12:28:55 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2010-12-21 09:33:32 +0000
@@ -95,6 +95,10 @@
 * Check sphinx compatibility for tests requiring older sphinx versions.
   (Vincent Ladeuil, #688072)
 
+* ``TestCase._captureVar`` and ``TestCase._old_env`` have been deleted due to
+  bug #690563. Test writers are encouraged to use ``TestCase.overrideEnv``
+  instead. (Vincent Ladeuil)
+
 * ``TestDebuntuExpansions`` was escaping the test isolation by calling the
   wrong base class ``setUp``. (Vincent Ladeuil, #684622)
 



More information about the bazaar-commits mailing list