mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #26942 -- Added support for subtests during parallel testing.
This commit is contained in:
parent
a02b5848ae
commit
42dcceba61
3 changed files with 105 additions and 4 deletions
67
tests/test_runner/test_parallel.py
Normal file
67
tests/test_runner/test_parallel.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
import unittest
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.runner import RemoteTestResult
|
||||
from django.utils import six
|
||||
|
||||
try:
|
||||
import tblib
|
||||
except ImportError:
|
||||
tblib = None
|
||||
|
||||
|
||||
class ParallelTestRunnerTest(SimpleTestCase):
|
||||
"""
|
||||
End-to-end tests of the parallel test runner.
|
||||
|
||||
These tests are only meaningful when running tests in parallel using
|
||||
the --parallel option, though it doesn't hurt to run them not in
|
||||
parallel.
|
||||
"""
|
||||
|
||||
@unittest.skipUnless(six.PY3, 'subtests were added in Python 3.4')
|
||||
def test_subtest(self):
|
||||
"""
|
||||
Check that passing subtests work.
|
||||
"""
|
||||
for i in range(2):
|
||||
with self.subTest(index=i):
|
||||
self.assertEqual(i, i)
|
||||
|
||||
|
||||
class SampleFailingSubtest(SimpleTestCase):
|
||||
|
||||
# This method name doesn't begin with "test" to prevent test discovery
|
||||
# from seeing it.
|
||||
def dummy_test(self):
|
||||
"""
|
||||
A dummy test for testing subTest failures.
|
||||
"""
|
||||
for i in range(3):
|
||||
with self.subTest(index=i):
|
||||
self.assertEqual(i, 1)
|
||||
|
||||
|
||||
class RemoteTestResultTest(SimpleTestCase):
|
||||
|
||||
@unittest.skipUnless(six.PY3 and tblib is not None, 'requires tblib to be installed')
|
||||
def test_add_failing_subtests(self):
|
||||
"""
|
||||
Failing subtests are added correctly using addSubTest().
|
||||
"""
|
||||
# Manually run a test with failing subtests to prevent the failures
|
||||
# from affecting the actual test run.
|
||||
result = RemoteTestResult()
|
||||
subtest_test = SampleFailingSubtest(methodName='dummy_test')
|
||||
subtest_test.run(result=result)
|
||||
|
||||
events = result.events
|
||||
self.assertEqual(len(events), 4)
|
||||
|
||||
event = events[1]
|
||||
self.assertEqual(event[0], 'addSubTest')
|
||||
self.assertEqual(str(event[2]), 'dummy_test (test_runner.test_parallel.SampleFailingSubtest) (index=0)')
|
||||
self.assertEqual(repr(event[3][1]), "AssertionError('0 != 1',)")
|
||||
|
||||
event = events[2]
|
||||
self.assertEqual(repr(event[3][1]), "AssertionError('2 != 1',)")
|
Loading…
Add table
Add a link
Reference in a new issue