#35794: Error in setUpTestData() with --parallel test execution causes abort
with
unclear exception and stack trace
-------------------------------------+-------------------------------------
Reporter: Glenn Matthews | Type:
| Uncategorized
Status: new | Component: Testing
| framework
Version: 4.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Given the following toy test example:
{{{
from django.test import TestCase
class AbortingTest(TestCase):
@classmethod
def setUpTestData(cls):
raise RuntimeError("Boo!")
def test_pass(self):
pass
class AnotherAbortingTest(TestCase):
@classmethod
def setUpTestData(cls):
raise RuntimeError("Boo Too!")
def test_pass(self):
pass
}}}
the errors are reported clearly when running tests in sequence (without
`--parallel`):
{{{
EE
======================================================================
ERROR: setUpClass (tests.test_error.AbortingTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/django/test/testcases.py",
line 1466, in setUpClass
cls.setUpTestData()
File "tests/test_error.py", line 7, in setUpTestData
raise RuntimeError("Boo!")
RuntimeError: Boo!
======================================================================
ERROR: setUpClass (tests.test_error.AnotherAbortingTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/django/test/testcases.py",
line 1466, in setUpClass
cls.setUpTestData()
File "tests/test_error.py", line 16, in setUpTestData
raise RuntimeError("Boo Too!")
RuntimeError: Boo Too!
----------------------------------------------------------------------
}}}
**However**, when tests are run with `--parallel`, test execution instead
aborts with a very unclear stack trace that doesn't even include any of
the test code in question:
{{{
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Emptying test database "default"...
Database default emptied!
Preserving test database for alias 'default'...
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-
packages/django/core/management/__init__.py", line 442, in
execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.12/site-
packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.12/site-
packages/django/core/management/commands/test.py", line 24, in
run_from_argv
super().run_from_argv(argv)
File "/usr/local/lib/python3.12/site-
packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.12/site-
packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-
packages/django/core/management/commands/test.py", line 68, in handle
failures = test_runner.run_tests(test_labels)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/test/runner.py",
line 1061, in run_tests
result = self.run_suite(suite)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/test/runner.py",
line 983, in run_suite
return runner.run(suite)
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/unittest/runner.py", line 240, in run
test(result)
File "/usr/local/lib/python3.12/unittest/suite.py", line 84, in __call__
return self.run(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/test/runner.py",
line 549, in run
handler(test, *args)
File "/usr/local/lib/python3.12/unittest/runner.py", line 101, in
addError
super(TextTestResult, self).addError(test, err)
File "/usr/local/lib/python3.12/unittest/result.py", line 17, in inner
return method(self, *args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/unittest/result.py", line 116, in
addError
self.errors.append((test, self._exc_info_to_string(err, test)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/unittest/result.py", line 195, in
_exc_info_to_string
output = sys.stdout.getvalue()
^^^^^^^^^^^^^^^^^^^
AttributeError: '_io.TextIOWrapper' object has no attribute 'getvalue'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35794>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701922f44f5b5-10720483-53e8-482a-9eaa-69ce9f10c78c-000000%40eu-central-1.amazonses.com.