Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linux): Fix detection of unit tests #9606

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion linux/keyman-config/keyman_config/sentry_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import platform
import sys
import traceback
from keyman_config.version import (
__version__,
__versionwithtag__,
Expand Down Expand Up @@ -47,7 +48,7 @@ def initialize_sentry(self):
return (True, '')

def is_sentry_enabled(self):
if 'unittest' in sys.modules.keys():
if self._is_unit_test():
return (False, 'Running unit tests, not reporting to Sentry')
elif self._get_environ_nosentry():
return (False, 'Not reporting to Sentry because KEYMAN_NOSENTRY environment variable set')
Expand Down Expand Up @@ -75,6 +76,14 @@ def _get_environ_nosentry(self):
keyman_nosentry = os.environ.get('KEYMAN_NOSENTRY')
return keyman_nosentry and (int(keyman_nosentry) == 1)

def _is_unit_test(self): # sourcery skip: use-any, use-next
# The suggested refactorings (using any() or next()) don't work
# when testing on Ubuntu 20.04
for line in traceback.format_stack():
if '/unittest/' in line:
return True
return False

def _handle_enabled(self, enabled):
if enabled:
self.initialize_sentry()
Expand Down