2121from openfeature .exception import ErrorCode , GeneralError , ProviderFatalError
2222from openfeature .hook import Hook
2323from openfeature .provider import FeatureProvider , Metadata , ProviderStatus
24+ from openfeature .provider ._registry import provider_registry
2425from openfeature .provider .no_op_provider import NoOpProvider
26+ from openfeature .transaction_context import (
27+ ContextVarsTransactionContextPropagator ,
28+ get_transaction_context ,
29+ set_transaction_context_propagator ,
30+ )
2531
2632
2733def test_should_not_raise_exception_with_noop_client ():
@@ -198,6 +204,7 @@ def test_should_not_shutdown_provider_bound_to_another_domain():
198204 provider .shutdown .assert_not_called ()
199205
200206
207+ # Requirement 1.6.1
201208def test_shutdown_should_shutdown_every_registered_provider_once ():
202209 # Given
203210 provider_1 = MagicMock (spec = FeatureProvider )
@@ -215,6 +222,35 @@ def test_shutdown_should_shutdown_every_registered_provider_once():
215222 provider_2 .shutdown .assert_called_once ()
216223
217224
225+ # Requirement 1.6.2
226+ def test_shutdown_should_reset_api_state ():
227+ # Given
228+ set_provider (MagicMock (spec = FeatureProvider ))
229+ add_hooks ([MagicMock (spec = Hook )])
230+ set_evaluation_context (EvaluationContext ("targeting_key" , {"attr1" : "val1" }))
231+ set_transaction_context_propagator (ContextVarsTransactionContextPropagator ())
232+
233+ # When
234+ shutdown ()
235+
236+ # Then
237+ provider = provider_registry .get_default_provider ()
238+ assert isinstance (provider , NoOpProvider )
239+
240+ hooks = get_hooks ()
241+ assert not hooks
242+
243+ evaluation_context = get_evaluation_context ()
244+ assert evaluation_context .targeting_key is None
245+ assert not evaluation_context .attributes
246+
247+ transaction_context = (
248+ get_transaction_context ()
249+ ) # NoOpTransactionContextPropagator returns a default context
250+ assert transaction_context .targeting_key is None
251+ assert not transaction_context .attributes
252+
253+
218254def test_clear_providers_shutdowns_every_provider_and_resets_default_provider ():
219255 # Given
220256 provider_1 = MagicMock (spec = FeatureProvider )
0 commit comments