summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-12-18 21:39:15 +0100
committerTim Graham <timograham@gmail.com>2014-12-19 14:26:46 -0500
commitea1865223886295674422923a2a9d38bacb0564d (patch)
tree9f5e8521dd5e6b6ba87b42ab343b82fde05a4bfa /tests
parenta970d6d941c849eba482b6a4b254c28f5e15524c (diff)
[1.7.x] Made model_regress unpickling test CWD-independent
Refs #24007. Thanks Tim Graham for his help with the patch. Backport of 1d9fc5caa947ff4ee72180185e91a9a145171712 and 995be4a1375340a53668dd80444756d77302000d from master
Diffstat (limited to 'tests')
-rw-r--r--tests/model_regress/tests.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py
index f17c134ac9..7e67d50aba 100644
--- a/tests/model_regress/tests.py
+++ b/tests/model_regress/tests.py
@@ -2,13 +2,14 @@ from __future__ import unicode_literals
import datetime
from operator import attrgetter
+import os
import pickle
import subprocess
import sys
-import tempfile
import unittest
from django.core.exceptions import ValidationError
+from django.core.files.temp import NamedTemporaryFile
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
from django.utils.timezone import get_fixed_timezone
@@ -272,11 +273,19 @@ print(article.headline)"""
article_text="This is an article",
)
- with tempfile.NamedTemporaryFile(mode='w+', suffix=".py", dir='.', delete=True) as script:
+ with NamedTemporaryFile(mode='w+', suffix=".py", dir='.') as script:
script.write(script_template % pickle.dumps(a))
script.flush()
try:
- result = subprocess.check_output(['python', script.name])
+ result = subprocess.check_output(
+ [sys.executable, script.name],
+ env={
+ # Needed to run test outside of tests directory
+ str('PYTHONPATH'): os.pathsep.join(sys.path),
+ # Needed on Windows because http://bugs.python.org/issue8557
+ str('PATH'): os.environ['PATH'],
+ }
+ )
except subprocess.CalledProcessError:
self.fail("Unable to reload model pickled data")
self.assertEqual(result.strip().decode(), "Some object")