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 @@ -168,21 +168,22 @@ async def runner():
168168 }
169169
170170
171- def test_launchdarkly_integration_did_not_enable (sentry_init , uninstall_integration ):
172- """
173- Setup should fail when using global client and ldclient.set_config wasn't called.
174-
175- We're accessing ldclient internals to set up this test, so it might break if launchdarkly's
176- implementation changes.
177- """
178-
171+ def test_launchdarkly_integration_did_not_enable (monkeypatch ):
172+ # Client is not passed in and set_config wasn't called.
173+ # TODO: Bad practice to access internals like this. We can skip this test, or remove this
174+ # case entirely (force user to pass in a client instance).
179175 ldclient ._reset_client ()
180176 try :
181177 ldclient .__lock .lock ()
182178 ldclient .__config = None
183179 finally :
184180 ldclient .__lock .unlock ()
185181
186- uninstall_integration (LaunchDarklyIntegration .identifier )
187182 with pytest .raises (DidNotEnable ):
188- sentry_init (integrations = [LaunchDarklyIntegration ()])
183+ LaunchDarklyIntegration ()
184+
185+ # Client not initialized.
186+ client = LDClient (config = Config ("sdk-key" ))
187+ monkeypatch .setattr (client , "is_initialized" , lambda : False )
188+ with pytest .raises (DidNotEnable ):
189+ LaunchDarklyIntegration (ld_client = client )
You can’t perform that action at this time.
0 commit comments