Opened 8 weeks ago
Closed 8 weeks ago
#35794 closed Uncategorized (invalid)
Error in setUpTestData() with --parallel test execution causes abort with unclear exception and stack trace
Reported by: | Glenn Matthews | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | 4.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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'
Note:
See TracTickets
for help on using tickets.
I couldn't replicate this on main with tblib installed (refs #25497)
If you have tblib installed, and are still getting an error on main, feel free to reopen with more details