diff options
author | Caio Ariede <caio.ariede@gmail.com> | 2019-06-05 11:35:36 -0300 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-08 12:11:06 +0200 |
commit | dafdfd6a60638c4edcca7c4e65d11c0af654d759 (patch) | |
tree | 6d7b9388c88a001524486383bf4a9938e01ad2e8 /docs/topics | |
parent | a28d1b38e55cf588cfaae97de6a575d5c9f90a96 (diff) | |
download | django-dafdfd6a60638c4edcca7c4e65d11c0af654d759.tar.gz |
Fixed #28790 -- Doc'd how to avoid running certain test classes in parallel.
Diffstat (limited to 'docs/topics')
-rw-r--r-- | docs/topics/testing/advanced.txt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt index d402ea93a6..ff2d9b8a7b 100644 --- a/docs/topics/testing/advanced.txt +++ b/docs/topics/testing/advanced.txt @@ -299,6 +299,40 @@ Advanced features of ``TransactionTestCase`` Using ``reset_sequences = True`` will slow down the test, since the primary key reset is a relatively expensive database operation. +.. _topics-testing-enforce-run-sequentially: + +Enforce running test classes sequentially +========================================= + +If you have test classes that cannot be run in parallel (e.g. because they +share a common resource), you can use ``django.test.testcases.SerializeMixin`` +to run them sequentially. This mixin uses a filesystem ``lockfile``. + +For example, you can use ``__file__`` to determine that all test classes in the +same file that inherit from ``SerializeMixin`` will run sequentially:: + + import os + + from django.test import TestCase + from django.test.testcases import SerializeMixin + + class ImageTestCaseMixin(SerializeMixin): + lockfile = __file__ + + def setUp(self): + self.filename = os.path.join(temp_storage_dir, 'my_file.png') + self.file = create_file(self.filename) + + class RemoveImageTests(ImageTestCaseMixin, TestCase): + def test_remove_image(self): + os.remove(self.filename) + self.assertFalse(os.path.exists(self.filename)) + + class ResizeImageTests(ImageTestCaseMixin, TestCase): + def test_resize_image(self): + resize_image(self.file, (48, 48)) + self.assertEqual(get_image_size(self.file), (48, 48)) + .. _testing-reusable-applications: Using the Django test runner to test reusable applications |