Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoided modifying current environment in admin_scripts tests

  • Loading branch information...
commit 56c80e8b4433df13e2b79f9ac4591d9a970398f5 1 parent 8446a24
@claudep claudep authored
Showing with 7 additions and 13 deletions.
  1. +7 −13 tests/admin_scripts/tests.py
View
20 tests/admin_scripts/tests.py
@@ -122,35 +122,29 @@ def run_test(self, script, args, settings_file=None, apps=None):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.