summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-09-09 14:08:35 -0400
committerTim Graham <timograham@gmail.com>2015-09-09 14:35:51 -0400
commiteaa3c883450f3c7ea939992ed075257bbac3d8b2 (patch)
treeb555699a8e2e3d59552c41debbdb8c1e60d34f30
parent4283a038431ef6428d086d4911179bd8eb8b2299 (diff)
Refs #22258 -- Fixed an unclosed temporary file in fixtures test.
This prevented the temporary directory from being removed on Windows.
-rw-r--r--tests/fixtures/tests.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index 4c0c9ee88f..a89b33aa65 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -9,6 +9,7 @@ import warnings
from django.apps import apps
from django.contrib.sites.models import Site
from django.core import management
+from django.core.files.temp import NamedTemporaryFile
from django.core.serializers.base import ProgressBar
from django.db import IntegrityError, connection
from django.test import (
@@ -295,22 +296,22 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
management.call_command('loaddata', 'fixture1.json', verbosity=0)
new_io = six.StringIO()
new_io.isatty = lambda: True
- _, filename = tempfile.mkstemp()
- options = {
- 'format': 'json',
- 'stdout': new_io,
- 'stderr': new_io,
- 'output': filename,
- }
- management.call_command('dumpdata', 'fixtures', **options)
- self.assertTrue(new_io.getvalue().endswith('[' + '.' * ProgressBar.progress_width + ']\n'))
+ with NamedTemporaryFile() as file:
+ options = {
+ 'format': 'json',
+ 'stdout': new_io,
+ 'stderr': new_io,
+ 'output': file.name,
+ }
+ management.call_command('dumpdata', 'fixtures', **options)
+ self.assertTrue(new_io.getvalue().endswith('[' + '.' * ProgressBar.progress_width + ']\n'))
- # Test no progress bar when verbosity = 0
- options['verbosity'] = 0
- new_io = six.StringIO()
- new_io.isatty = lambda: True
- management.call_command('dumpdata', 'fixtures', **options)
- self.assertEqual(new_io.getvalue(), '')
+ # Test no progress bar when verbosity = 0
+ options['verbosity'] = 0
+ new_io = six.StringIO()
+ new_io.isatty = lambda: True
+ management.call_command('dumpdata', 'fixtures', **options)
+ self.assertEqual(new_io.getvalue(), '')
def test_compress_format_loading(self):
# Load fixture 4 (compressed), using format specification