summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid D. Riddle <ddriddle@illinois.edu>2015-04-28 11:59:05 -0500
committerTim Graham <timograham@gmail.com>2015-04-29 12:28:39 -0400
commit8c58caaf9dbd2c8769f27133d70784c7d74791ce (patch)
tree1bd3927969f6338c2189546a316da26b2bd55449
parentd5fb31da17373091805bcecec62cfb4359287eac (diff)
[1.8.x] Fixed #24717 -- Fixed model_regress test failure on RHEL6 SCL
The test failed on RHEL6 systems running python 2.7 from a RedHat Software Collection (SCL) because this test runs an external python script with a stripped system environment. RedHat SCLs work by setting a number of system environment variables when these are stripped out by this test the python 2.7 interpreter is no longer able to function properly because it can not find the system libraries needed. Now we use use mock to modify the system environment directly. Backport of 31e6c9c8e310e68a96c1f76b9657242c6cecaa4d from master
-rw-r--r--tests/model_regress/test_pickle.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/tests/model_regress/test_pickle.py b/tests/model_regress/test_pickle.py
index 1666eb2549..607f495f3e 100644
--- a/tests/model_regress/test_pickle.py
+++ b/tests/model_regress/test_pickle.py
@@ -7,7 +7,8 @@ import warnings
from django.core.files.temp import NamedTemporaryFile
from django.db import DJANGO_VERSION_PICKLE_KEY, models
-from django.test import TestCase
+from django.test import TestCase, mock
+from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.version import get_version
@@ -84,19 +85,16 @@ print(article.headline)"""
with NamedTemporaryFile(mode='w+', suffix=".py") as script:
script.write(script_template % pickle.dumps(a))
script.flush()
- pythonpath = [os.path.dirname(script.name)] + sys.path
- env = {
- # Needed to run test outside of tests directory
- str('PYTHONPATH'): os.pathsep.join(pythonpath),
- # Needed on Windows because http://bugs.python.org/issue8557
- str('PATH'): os.environ['PATH'],
- str('TMPDIR'): os.environ['TMPDIR'],
- str('LANG'): os.environ.get('LANG', ''),
- }
- if 'SYSTEMROOT' in os.environ: # Windows http://bugs.python.org/issue20614
- env[str('SYSTEMROOT')] = os.environ['SYSTEMROOT']
- try:
- result = subprocess.check_output([sys.executable, script.name], env=env)
- except subprocess.CalledProcessError:
- self.fail("Unable to reload model pickled data")
+ # A path to model_regress must be set in PYTHONPATH
+ model_regress_dir = os.path.dirname(upath(__file__))
+ model_regress_path = os.path.abspath(model_regress_dir)
+ tests_path = os.path.split(model_regress_path)[0]
+ pythonpath = os.environ.get('PYTHONPATH', '')
+ pythonpath = os.pathsep.join([tests_path, pythonpath])
+
+ with mock.patch.dict('os.environ', {'PYTHONPATH': pythonpath}):
+ try:
+ result = subprocess.check_output([sys.executable, script.name])
+ except subprocess.CalledProcessError:
+ self.fail("Unable to reload model pickled data")
self.assertEqual(result.strip().decode(), "Some object")