From ea1865223886295674422923a2a9d38bacb0564d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 18 Dec 2014 21:39:15 +0100 Subject: [PATCH] [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 --- tests/model_regress/tests.py | 15 ++++++++++++--- 1 file 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")