From 374989a2ada961e286e2ff25a9773d56c5649c3d Mon Sep 17 00:00:00 2001 From: bendikro Date: Tue, 15 Dec 2015 18:26:29 +0100 Subject: [PATCH] [Tests] Catch and print errors in setup/teardown --- deluge/tests/basetest.py | 16 +++++++++++++--- deluge/ui/web/auth.py | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/deluge/tests/basetest.py b/deluge/tests/basetest.py index 478ba398e..c9e6df22d 100644 --- a/deluge/tests/basetest.py +++ b/deluge/tests/basetest.py @@ -19,16 +19,26 @@ class BaseTestCase(unittest.TestCase): warnings.warn("The component._ComponentRegistry.components is not empty on test setup." "This is probably caused by another test that didn't clean up after finishing!: %s" % component._ComponentRegistry.components) - return self.set_up() + d = maybeDeferred(self.set_up) + + def on_setup_error(error): + warnings.warn("Error caught in test setup!\n%s" % error.getTraceback()) + self.fail() + + return d.addErrback(on_setup_error) def tearDown(self): # NOQA d = maybeDeferred(self.tear_down) - def on_teared_down(result): + def on_teardown_failed(error): + warnings.warn("Error caught in test teardown!\n%s" % error.getTraceback()) + self.fail() + + def on_teardown_complete(result): component._ComponentRegistry.components.clear() component._ComponentRegistry.dependents.clear() - return d.addCallback(on_teared_down) + return d.addCallbacks(on_teardown_complete, on_teardown_failed) def set_up(self): pass diff --git a/deluge/ui/web/auth.py b/deluge/ui/web/auth.py index 5ede83fde..d90273aea 100644 --- a/deluge/ui/web/auth.py +++ b/deluge/ui/web/auth.py @@ -82,8 +82,13 @@ class Auth(JSONComponent): def __init__(self): super(Auth, self).__init__("Auth") self.worker = LoopingCall(self._clean_sessions) + + def start(self): self.worker.start(5) + def stop(self): + self.worker.stop() + def _clean_sessions(self): config = component.get("DelugeWeb").config session_ids = config["sessions"].keys()