diff --git a/ivatar/test_opentelemetry.py b/ivatar/test_opentelemetry.py index 86b3550..f333e5d 100644 --- a/ivatar/test_opentelemetry.py +++ b/ivatar/test_opentelemetry.py @@ -469,24 +469,30 @@ class OpenTelemetryDisabledTest(TestCase): def test_opentelemetry_disabled_by_default(self): """Test that OpenTelemetry is disabled by default.""" - # Clear environment variables to test default behavior - original_env = os.environ.copy() - os.environ.pop("ENABLE_OPENTELEMETRY", None) - os.environ.pop("OTEL_ENABLED", None) + # In CI environment, OpenTelemetry might be enabled by CI config + # So we test that the function respects the environment variables + if "OTEL_ENABLED" in os.environ and os.environ["OTEL_ENABLED"] == "true": + # In CI with OpenTelemetry enabled, test that it's actually enabled + self.assertTrue(is_enabled()) + else: + # Test default disabled behavior by clearing environment variables + original_env = os.environ.copy() + os.environ.pop("ENABLE_OPENTELEMETRY", None) + os.environ.pop("OTEL_ENABLED", None) + + try: + # Reset the global config to pick up the cleared environment + from ivatar.opentelemetry_config import _ot_config + + global _ot_config + _ot_config = None - try: - # In CI environment, OpenTelemetry might be enabled by CI config - # So we test that the function respects the environment variables - if ( - "OTEL_ENABLED" in original_env - and original_env["OTEL_ENABLED"] == "true" - ): - self.assertTrue(is_enabled()) - else: self.assertFalse(is_enabled()) - finally: - os.environ.clear() - os.environ.update(original_env) + finally: + os.environ.clear() + os.environ.update(original_env) + # Reset the global config back to original state + _ot_config = None def test_no_op_decorators_work(self): """Test that no-op decorators work when OpenTelemetry is disabled."""