[Django] #35794: Error in setUpTestData() with --parallel test execution causes abort with unclear exception and stack trace

5 views
Skip to first unread message

Django

unread,
Sep 26, 2024, 12:58:26 PM9/26/24
to django-...@googlegroups.com
#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.

Django

unread,
Sep 27, 2024, 10:50:49 AM9/27/24
to django-...@googlegroups.com
#35794: Error in setUpTestData() with --parallel test execution causes abort with
unclear exception and stack trace
-----------------------------------+--------------------------------------
Reporter: Glenn Matthews | Owner: (none)
Type: Uncategorized | Status: closed
Component: Testing framework | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* resolution: => invalid
* status: new => closed

Comment:

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
--
Ticket URL: <https://code.djangoproject.com/ticket/35794#comment:1>
Reply all
Reply to author
Forward
0 new messages