summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-03-08 12:32:57 +0100
committerClaude Paroz <claude@2xlibre.net>2014-03-08 12:32:57 +0100
commit56c80e8b4433df13e2b79f9ac4591d9a970398f5 (patch)
tree0ed2a98bf4c1bb7a324b3a5b4b9240120e0c6911 /tests/admin_scripts
parent8446a2438ffeab845e31cba4489f03fccc387298 (diff)
Avoided modifying current environment in admin_scripts tests
Diffstat (limited to 'tests/admin_scripts')
-rw-r--r--tests/admin_scripts/tests.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 289f0bdd65..5564c771c9 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -122,35 +122,29 @@ class AdminScriptTestCase(unittest.TestCase):
django_dir = os.path.dirname(tests_dir)
ext_backend_base_dirs = self._ext_backend_paths()
- # Remember the old environment
- old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
+ # Define a temporary environment for the subprocess
+ test_environ = os.environ.copy()
if sys.platform.startswith('java'):
python_path_var_name = 'JYTHONPATH'
else:
python_path_var_name = 'PYTHONPATH'
- old_python_path = os.environ.get(python_path_var_name, None)
old_cwd = os.getcwd()
# Set the test environment
if settings_file:
- os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
- elif 'DJANGO_SETTINGS_MODULE' in os.environ:
- del os.environ['DJANGO_SETTINGS_MODULE']
+ test_environ['DJANGO_SETTINGS_MODULE'] = settings_file
+ elif 'DJANGO_SETTINGS_MODULE' in test_environ:
+ del test_environ['DJANGO_SETTINGS_MODULE']
python_path = [base_dir, django_dir, tests_dir]
python_path.extend(ext_backend_base_dirs)
- os.environ[python_path_var_name] = os.pathsep.join(python_path)
+ test_environ[python_path_var_name] = os.pathsep.join(python_path)
# Move to the test directory and run
os.chdir(test_dir)
out, err = subprocess.Popen([sys.executable, script] + args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- universal_newlines=True).communicate()
- # Restore the old environment
- if old_django_settings_module:
- os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
- if old_python_path:
- os.environ[python_path_var_name] = old_python_path
+ env=test_environ, universal_newlines=True).communicate()
# Move back to the old working directory
os.chdir(old_cwd)