[1.7.x] Made model_regress unpickling test CWD-independent
Refs #24007. Thanks Tim Graham for his help with the patch. Backport of1d9fc5caa9
and995be4a137
from master
This commit is contained in:
parent
a970d6d941
commit
ea18652238
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue