Skip to content

Commit 725bf63

Browse files
committed
Adds new method to check if running unit tests
1 parent a0475d6 commit 725bf63

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/clusterfuzz/_internal/metrics/logs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ def _file_logging_enabled() -> bool:
104104
def _cloud_logging_enabled() -> bool:
105105
"""Return bool True where Google Cloud Logging is enabled.
106106
This is enabled by default but disabled for local development."""
107-
return environment.get_value('LOG_TO_GCP',
108-
True) and (not os.getenv('PY_UNITTESTS') and
109-
not _is_local())
107+
return (environment.get_value('LOG_TO_GCP', True) and
108+
not environment.is_running_unit_tests() and not _is_local())
110109

111110

112111
def suppress_unwanted_warnings():
@@ -412,7 +411,7 @@ def configure_appengine():
412411
"""Configure logging for App Engine."""
413412
logging.getLogger().setLevel(logging.INFO)
414413

415-
if os.getenv('LOCAL_DEVELOPMENT') or os.getenv('PY_UNITTESTS'):
414+
if os.getenv('LOCAL_DEVELOPMENT') or environment.is_running_unit_tests():
416415
return
417416

418417
import google.cloud.logging

src/clusterfuzz/_internal/system/environment.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,3 +1236,8 @@ def can_testcase_run_on_platform(testcase_platform_id, current_platform_id):
12361236

12371237
def is_tworker():
12381238
return get_value('TWORKER', False)
1239+
1240+
1241+
def is_running_unit_tests() -> bool:
1242+
"""Returns whether or not we're running unit tests."""
1243+
return get_value('PY_UNITTESTS', False)

0 commit comments

Comments
 (0)