File tree Expand file tree Collapse file tree 2 files changed +18
-17
lines changed
tests/integrations/launchdarkly Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change 2020
2121class LaunchDarklyIntegration (Integration ):
2222 identifier = "launchdarkly"
23- _ld_client = None # type: LDClient | None
2423
2524 def __init__ (self , ld_client = None ):
2625 # type: (LDClient | None) -> None
2726 """
2827 :param client: An initialized LDClient instance. If a client is not provided, this
2928 integration will attempt to use the shared global instance.
3029 """
31- self .__class__ ._ld_client = ld_client
32-
33- @staticmethod
34- def setup_once ():
35- # type: () -> None
3630 try :
37- client = LaunchDarklyIntegration . _ld_client or ldclient .get ()
31+ client = ld_client or ldclient .get ()
3832 except Exception as exc :
3933 raise DidNotEnable ("Error getting LaunchDarkly client. " + repr (exc ))
4034
35+ if not client .is_initialized ():
36+ raise DidNotEnable ("LaunchDarkly client is not initialized." )
37+
4138 # Register the flag collection hook with the LD client.
4239 client .add_hook (LaunchDarklyHook ())
4340
41+ @staticmethod
42+ def setup_once ():
43+ # type: () -> None
4444 scope = sentry_sdk .get_current_scope ()
4545 scope .add_error_processor (flag_error_processor )
4646
Original file line number Diff line number Diff line change @@ -183,21 +183,22 @@ async def runner():
183183 }
184184
185185
186- def test_launchdarkly_integration_did_not_enable (sentry_init , uninstall_integration ):
187- """
188- Setup should fail when using global client and ldclient.set_config wasn't called.
189-
190- We're accessing ldclient internals to set up this test, so it might break if launchdarkly's
191- implementation changes.
192- """
193-
186+ def test_launchdarkly_integration_did_not_enable (monkeypatch ):
187+ # Client is not passed in and set_config wasn't called.
188+ # TODO: Bad practice to access internals like this. We can skip this test, or remove this
189+ # case entirely (force user to pass in a client instance).
194190 ldclient ._reset_client ()
195191 try :
196192 ldclient .__lock .lock ()
197193 ldclient .__config = None
198194 finally :
199195 ldclient .__lock .unlock ()
200196
201- uninstall_integration (LaunchDarklyIntegration .identifier )
202197 with pytest .raises (DidNotEnable ):
203- sentry_init (integrations = [LaunchDarklyIntegration ()])
198+ LaunchDarklyIntegration ()
199+
200+ # Client not initialized.
201+ client = LDClient (config = Config ("sdk-key" ))
202+ monkeypatch .setattr (client , "is_initialized" , lambda : False )
203+ with pytest .raises (DidNotEnable ):
204+ LaunchDarklyIntegration (ld_client = client )
You can’t perform that action at this time.
0 commit comments