From b799a50c8e4461121b52659970c21a58b4067651 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 5 Feb 2015 22:33:13 +0100 Subject: [PATCH] Serialized some tests that interact with the filesystem. Considering the APIs exercised by these test cases, it's hard to make them independent. --- tests/i18n/test_extraction.py | 16 ++++++++++------ tests/model_fields/test_imagefield.py | 5 ++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index 4a612c546b..b9c4b4fc3e 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -17,6 +17,7 @@ from django.core.management.commands.makemessages import \ Command as MakeMessagesCommand from django.core.management.utils import find_command from django.test import SimpleTestCase, mock, override_settings +from django.test.testcases import SerializeMixin from django.test.utils import captured_stderr, captured_stdout from django.utils import six from django.utils._os import upath @@ -30,7 +31,13 @@ this_directory = os.path.dirname(upath(__file__)) @skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests') -class ExtractorTests(SimpleTestCase): +class ExtractorTests(SerializeMixin, SimpleTestCase): + + # makemessages scans the current working directory and writes in the + # locale subdirectory. There aren't any options to control this. As a + # consequence tests can't run in parallel. Since i18n tests run in less + # than 4 seconds, serializing them with SerializeMixin is acceptable. + lockfile = __file__ test_dir = os.path.abspath(os.path.join(this_directory, 'commands')) @@ -610,9 +617,6 @@ class KeepPotFileExtractorTests(ExtractorTests): POT_FILE = 'locale/django.pot' - def setUp(self): - super(KeepPotFileExtractorTests, self).setUp() - def tearDown(self): super(KeepPotFileExtractorTests, self).tearDown() os.chdir(self.test_dir) @@ -646,6 +650,7 @@ class MultipleLocaleExtractionTests(ExtractorTests): LOCALES = ['pt', 'de', 'ch'] def tearDown(self): + super(MultipleLocaleExtractionTests, self).tearDown() os.chdir(self.test_dir) for locale in self.LOCALES: try: @@ -677,7 +682,6 @@ class ExcludedLocaleExtractionTests(ExtractorTests): def setUp(self): super(ExcludedLocaleExtractionTests, self).setUp() - os.chdir(self.test_dir) # ExtractorTests.tearDown() takes care of restoring. shutil.copytree('canned_locale', 'locale') self._set_times_for_all_po_files() @@ -719,7 +723,7 @@ class ExcludedLocaleExtractionTests(ExtractorTests): class CustomLayoutExtractionTests(ExtractorTests): def setUp(self): - self._cwd = os.getcwd() + super(CustomLayoutExtractionTests, self).setUp() self.test_dir = os.path.join(this_directory, 'project_dir') def test_no_locale_raises(self): diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py index c2908b06e4..8320fafaa8 100644 --- a/tests/model_fields/test_imagefield.py +++ b/tests/model_fields/test_imagefield.py @@ -8,6 +8,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.files import File from django.core.files.images import ImageFile from django.test import TestCase +from django.test.testcases import SerializeMixin from django.utils._os import upath try: @@ -27,11 +28,13 @@ else: PersonTwoImages = Person -class ImageFieldTestMixin(object): +class ImageFieldTestMixin(SerializeMixin): """ Mixin class to provide common functionality to ImageField test classes. """ + lockfile = __file__ + # Person model to use for tests. PersonModel = PersonWithHeightAndWidth # File class to use for file instances.