#25176: TestCase: an error in setUpTestData snowballs across the entire test
suite
-------------------------------------+-------------------------------------
Reporter: adamchainz | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Testing framework | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by adamchainz):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
https://github.com/django/django/pull/5051
I've struggled to add a test for this. I had the idea for something like
the below, but the problem is that if you try do any checking in the
exception handler in setUpClass you can then trigger tearDownClass even
though it shouldn't be run. I don't think there is a sane way of testing
it, except from creating tests that run a second set of tests where one
has a broken setUpTestData, and then asserting that only the one of the
second set failed.
{{{
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 7056ea3..ede8cca 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -2,6 +2,7 @@
from __future__ import unicode_literals
import unittest
+import sys
from django.conf.urls import url
from django.contrib.staticfiles.finders import get_finder, get_finders
@@ -744,6 +745,26 @@ class SkippingExtraTests(TestCase):
pass
+class TestBadSetupTestData(TestCase):
+
+ class MyException(Exception):
+ pass
+
+ @classmethod
+ def setUpClass(cls):
+ try:
+ super(TestBadSetupTestData, cls).setUpClass()
+ except cls.MyException:
+ assert not connection.in_atomic_block
+
+ @classmethod
+ def setUpTestData(cls):
+ raise cls.MyException()
+
+ def test_failure_in_setUpTestData_should_exit_cleanly(self):
+ pass
+
+
class AssertRaisesMsgTest(SimpleTestCase):
def test_special_re_chars(self):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25176#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.42ceb1af4281ccc14e5628177013414e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.