From d54f693aacd16c0d4b2cf7d0ba824cccf1c71a80 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Thu, 7 Dec 2023 10:28:33 +0000 Subject: [PATCH] Clear session tracker state between test cases This isn't _necessary_ to have the tests run, but not doing so causes any outstanding sessions to fail delivery after the server is torn down, which leads to a bunch of warnings --- tests/integrations/test_wsgi.py | 1 - tests/utils.py | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/integrations/test_wsgi.py b/tests/integrations/test_wsgi.py index 779b85d0..16e5015f 100644 --- a/tests/integrations/test_wsgi.py +++ b/tests/integrations/test_wsgi.py @@ -13,7 +13,6 @@ class SentinelError(RuntimeError): class TestWSGI(IntegrationTest): - def setUp(self): super(TestWSGI, self).setUp() bugsnag.configure( diff --git a/tests/utils.py b/tests/utils.py index e9cecfa8..441cd157 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -31,9 +31,17 @@ def setUp(self): self.server.sessions_received = [] def tearDown(self): - bugsnag.legacy.default_client.uninstall_sys_hook() - client = bugsnag.Client() - client.configuration.api_key = 'some key' + previous_client = bugsnag.legacy.default_client + previous_client.uninstall_sys_hook() + + if previous_client.session_tracker.delivery_thread is not None: + previous_client.session_tracker.delivery_thread.cancel() + previous_client.session_tracker.delivery_thread = None + + previous_client.session_tracker.session_counts = {} + + client = bugsnag.Client(api_key='some key') + bugsnag.legacy.default_client = client bugsnag.legacy.configuration = client.configuration