Skip to content

Commit 9b3bf85

Browse files
authored
Merge pull request #9606 from keymanapp/fix/linux/9577_testdetection
fix(linux): Fix detection of unit tests
2 parents e56c5ba + b208493 commit 9b3bf85

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

linux/keyman-config/keyman_config/sentry_handling.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import platform
77
import sys
8+
import traceback
89
from keyman_config.version import (
910
__version__,
1011
__versionwithtag__,
@@ -47,7 +48,7 @@ def initialize_sentry(self):
4748
return (True, '')
4849

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

79+
def _is_unit_test(self): # sourcery skip: use-any, use-next
80+
# The suggested refactorings (using any() or next()) don't work
81+
# when testing on Ubuntu 20.04
82+
for line in traceback.format_stack():
83+
if '/unittest/' in line:
84+
return True
85+
return False
86+
7887
def _handle_enabled(self, enabled):
7988
if enabled:
8089
self.initialize_sentry()

0 commit comments

Comments
 (0)