summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/admin/tests.py5
-rw-r--r--django/test/testcases.py8
2 files changed, 10 insertions, 3 deletions
diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py
index 78e68e79c2..f529faefce 100644
--- a/django/contrib/admin/tests.py
+++ b/django/contrib/admin/tests.py
@@ -17,13 +17,14 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
except Exception as e:
raise SkipTest('Selenium webdriver "%s" not installed or not '
'operational: %s' % (cls.webdriver_class, str(e)))
+ # This has to be last to ensure that resources are cleaned up properly!
super(AdminSeleniumWebDriverTestCase, cls).setUpClass()
@classmethod
- def tearDownClass(cls):
+ def _tearDownClassInternal(cls):
if hasattr(cls, 'selenium'):
cls.selenium.quit()
- super(AdminSeleniumWebDriverTestCase, cls).tearDownClass()
+ super(AdminSeleniumWebDriverTestCase, cls)._tearDownClassInternal()
def wait_until(self, callback, timeout=10):
"""
diff --git a/django/test/testcases.py b/django/test/testcases.py
index e556d18225..0941fa09d1 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1157,12 +1157,15 @@ class LiveServerTestCase(TransactionTestCase):
# Wait for the live server to be ready
cls.server_thread.is_ready.wait()
if cls.server_thread.error:
+ # Clean up behind ourselves, since tearDownClass won't get called in
+ # case of errors.
+ cls._tearDownClassInternal()
raise cls.server_thread.error
super(LiveServerTestCase, cls).setUpClass()
@classmethod
- def tearDownClass(cls):
+ def _tearDownClassInternal(cls):
# There may not be a 'server_thread' attribute if setUpClass() for some
# reasons has raised an exception.
if hasattr(cls, 'server_thread'):
@@ -1175,4 +1178,7 @@ class LiveServerTestCase(TransactionTestCase):
and conn.settings_dict['NAME'] == ':memory:'):
conn.allow_thread_sharing = False
+ @classmethod
+ def tearDownClass(cls):
+ cls._tearDownClassInternal()
super(LiveServerTestCase, cls).tearDownClass()