Skip to content

Commit

Permalink
Use identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
cmanallen committed Jan 3, 2025
1 parent 633b3ed commit 9ebee27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
11 changes: 2 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,9 @@ def reset_integrations():

@pytest.fixture
def uninstall_integration():
"""
Forces the next call to sentry_init to re-install an integration and call `setup_once`.
No effect if the integration is not installed.
"""
"""Use to force the next call to sentry_init to re-install/setup an integration."""

def inner(name_or_cls):
if isinstance(name_or_cls, str):
identifier = name_or_cls
else:
identifier = name_or_cls.identifier
def inner(identifier):
_processed_integrations.discard(identifier)
_installed_integrations.discard(identifier)

Expand Down
16 changes: 8 additions & 8 deletions tests/integrations/unleash/test_unleash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def test_is_enabled(sentry_init, capture_events, uninstall_integration):
uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)

with mock_unleash_client():
client = UnleashClient()
Expand All @@ -35,7 +35,7 @@ def test_is_enabled(sentry_init, capture_events, uninstall_integration):


def test_get_variant(sentry_init, capture_events, uninstall_integration):
uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)

with mock_unleash_client():
client = UnleashClient()
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_get_variant(sentry_init, capture_events, uninstall_integration):


def test_is_enabled_threaded(sentry_init, capture_events, uninstall_integration):
uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)

with mock_unleash_client():
client = UnleashClient()
Expand Down Expand Up @@ -113,7 +113,7 @@ def task(flag_key):


def test_get_variant_threaded(sentry_init, capture_events, uninstall_integration):
uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)

with mock_unleash_client():
client = UnleashClient()
Expand Down Expand Up @@ -164,7 +164,7 @@ def task(flag_key):
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_is_enabled_asyncio(sentry_init, capture_events, uninstall_integration):
asyncio = pytest.importorskip("asyncio")
uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)

with mock_unleash_client():
client = UnleashClient()
Expand Down Expand Up @@ -216,7 +216,7 @@ async def runner():
def test_get_variant_asyncio(sentry_init, capture_events, uninstall_integration):
asyncio = pytest.importorskip("asyncio")

uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)

with mock_unleash_client():
client = UnleashClient()
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_wraps_original(sentry_init, uninstall_integration):
client.is_enabled = mock_is_enabled
client.get_variant = mock_get_variant

uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)
sentry_init(integrations=[UnleashIntegration()]) # type: ignore

res = client.is_enabled("test-flag", "arg", kwarg=1)
Expand All @@ -298,7 +298,7 @@ def test_wrapper_attributes(sentry_init, uninstall_integration):
original_is_enabled = client.is_enabled
original_get_variant = client.get_variant

uninstall_integration(UnleashIntegration)
uninstall_integration(UnleashIntegration.identifier)
sentry_init(integrations=[UnleashIntegration()]) # type: ignore

# Mock clients methods have not lost their qualified names after decoration.
Expand Down

0 comments on commit 9ebee27

Please sign in to comment.