Rev 5587: Final tweaks and doc. in file:///home/vila/src/bzr/bugs/690563-better-env-isolation/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Dec 16 17:45:14 GMT 2010


At file:///home/vila/src/bzr/bugs/690563-better-env-isolation/

------------------------------------------------------------
revno: 5587
revision-id: v.ladeuil+lp at free.fr-20101216174514-wp972mm324u1muy1
parent: v.ladeuil+lp at free.fr-20101216171739-v93fl6q2b83sm8nn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 690563-better-env-isolation
timestamp: Thu 2010-12-16 18:45:14 +0100
message:
  Final tweaks and doc.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-12-16 17:17:39 +0000
+++ b/bzrlib/tests/__init__.py	2010-12-16 17:45:14 +0000
@@ -1541,9 +1541,10 @@
         return value
 
     def overrideEnv(self, name, new):
-        """Set an environment variable, and reset it when the test finished.
-
-        :param name: The name if the environment variable.
+        """Set an environment variable, and reset it fater the test.
+
+        :param name: The environment variable name.
+
         :param new: The value to set the variable to. If None, the 
             variable is deleted from the environment.
 

=== modified file 'doc/developers/testing.txt'
--- a/doc/developers/testing.txt	2010-12-09 00:18:26 +0000
+++ b/doc/developers/testing.txt	2010-12-16 17:45:14 +0000
@@ -977,6 +977,25 @@
 
     self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
 
+Temporarily changing environment variables
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If yout test needs to temporarily change some environment variable value
+(which generally means you want it restored at the end), you can use::
+
+    self.overrideEnv('BZR_ENV_VAR', 'new_value')
+
+If you want to remove a variable from the environment, you should use the
+special ``None`` value::
+
+    self.overrideEnv('PATH', None)
+
+If you add a new feature which depends on a new environment variable, make
+sure it behaves properly when this variable is not defined (if applicable) and
+if you need to enforce a specific default value, check the
+``TestCase._cleanEnvironment`` in ``bzrlib.tests.__init__.py`` which defines a
+proper set of values for all tests.
+
 Cleaning up
 ~~~~~~~~~~~
 



More information about the bazaar-commits mailing list