Refs #22258 -- Fixed an unclosed temporary file in fixtures test.

This prevented the temporary directory from being removed
on Windows.
This commit is contained in:
Tim Graham 2015-09-09 14:08:35 -04:00
parent 4283a03843
commit eaa3c88345
1 changed files with 16 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import warnings
from django.apps import apps from django.apps import apps
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core import management from django.core import management
from django.core.files.temp import NamedTemporaryFile
from django.core.serializers.base import ProgressBar from django.core.serializers.base import ProgressBar
from django.db import IntegrityError, connection from django.db import IntegrityError, connection
from django.test import ( from django.test import (
@ -295,12 +296,12 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command('loaddata', 'fixture1.json', verbosity=0) management.call_command('loaddata', 'fixture1.json', verbosity=0)
new_io = six.StringIO() new_io = six.StringIO()
new_io.isatty = lambda: True new_io.isatty = lambda: True
_, filename = tempfile.mkstemp() with NamedTemporaryFile() as file:
options = { options = {
'format': 'json', 'format': 'json',
'stdout': new_io, 'stdout': new_io,
'stderr': new_io, 'stderr': new_io,
'output': filename, 'output': file.name,
} }
management.call_command('dumpdata', 'fixtures', **options) management.call_command('dumpdata', 'fixtures', **options)
self.assertTrue(new_io.getvalue().endswith('[' + '.' * ProgressBar.progress_width + ']\n')) self.assertTrue(new_io.getvalue().endswith('[' + '.' * ProgressBar.progress_width + ']\n'))