Rev 5988: Make the test framework more robust against BZR_LOG leaks. in file:///home/vila/src/bzr/bugs/798698-bogus-log-files/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Jun 17 15:01:40 UTC 2011
At file:///home/vila/src/bzr/bugs/798698-bogus-log-files/
------------------------------------------------------------
revno: 5988
revision-id: v.ladeuil+lp at free.fr-20110617150140-mycsinau1tvbsb70
parent: v.ladeuil+lp at free.fr-20110617135923-kc4el63uldex6c5n
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 798698-bogus-log-files
timestamp: Fri 2011-06-17 17:01:40 +0200
message:
Make the test framework more robust against BZR_LOG leaks.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2011-06-17 13:40:01 +0000
+++ b/bzrlib/tests/__init__.py 2011-06-17 15:01:40 +0000
@@ -142,7 +142,10 @@
'BZREMAIL': None, # may still be present in the environment
'EMAIL': 'jrandom at example.com', # set EMAIL as bzr does not guess
'BZR_PROGRESS_BAR': None,
- 'BZR_LOG': None,
+ # This should trap leaks to ~/.bzr.log. This occurs when tests use TestCase
+ # as a base class instead of TestCaseInTempDir. Tests inheriting from
+ # TestCase should not use disk resources, BZR_LOG is one.
+ 'BZR_LOG': '/you-should-use-TestCaseInTempDir-if-you-need-a-log-file',
'BZR_PLUGIN_PATH': None,
'BZR_DISABLE_PLUGINS': None,
'BZR_PLUGINS_AT': None,
@@ -928,7 +931,7 @@
The method is really a factory and users are expected to use it as such.
"""
-
+
kwargs['setUp'] = isolated_doctest_setUp
kwargs['tearDown'] = isolated_doctest_tearDown
return doctest.DocTestSuite(*args, **kwargs)
@@ -2325,20 +2328,21 @@
class TestCaseWithMemoryTransport(TestCase):
"""Common test class for tests that do not need disk resources.
- Tests that need disk resources should derive from TestCaseWithTransport.
+ Tests that need disk resources should derive from TestCaseInTempDir
+ orTestCaseWithTransport.
TestCaseWithMemoryTransport sets the TEST_ROOT variable for all bzr tests.
- For TestCaseWithMemoryTransport the test_home_dir is set to the name of
+ For TestCaseWithMemoryTransport the ``test_home_dir`` is set to the name of
a directory which does not exist. This serves to help ensure test isolation
- is preserved. test_dir is set to the TEST_ROOT, as is cwd, because they
- must exist. However, TestCaseWithMemoryTransport does not offer local
- file defaults for the transport in tests, nor does it obey the command line
+ is preserved. ``test_dir`` is set to the TEST_ROOT, as is cwd, because they
+ must exist. However, TestCaseWithMemoryTransport does not offer local file
+ defaults for the transport in tests, nor does it obey the command line
override, so tests that accidentally write to the common directory should
be rare.
- :cvar TEST_ROOT: Directory containing all temporary directories, plus
- a .bzr directory that stops us ascending higher into the filesystem.
+ :cvar TEST_ROOT: Directory containing all temporary directories, plus a
+ ``.bzr`` directory that stops us ascending higher into the filesystem.
"""
TEST_ROOT = None
@@ -2668,6 +2672,12 @@
OVERRIDE_PYTHON = 'python'
+ def setUp(self):
+ super(TestCaseInTempDir, self).setUp()
+ # Remove the protection set in isolated_environ, we have a proper
+ # access to disk resources now.
+ self.overrideEnv('BZR_LOG', None)
+
def check_file_contents(self, filename, expect):
self.log("check contents of file %s" % filename)
f = file(filename)
More information about the bazaar-commits
mailing list