Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pytest_sentry/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ def _resolve_scope_marker_value_uncached(marker_value):

if isinstance(marker_value, str):
# If a DSN string is provided, create a new client and use that
scope = sentry_sdk.get_isolation_scope()
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
scope.set_client(Client(marker_value))
return scope

if isinstance(marker_value, dict):
# If a dict is provided, create a new client using the dict as Client options
scope = sentry_sdk.get_isolation_scope()
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
scope.set_client(Client(**marker_value))
return scope

if isinstance(marker_value, Client):
# If a Client instance is provided, use that
scope = sentry_sdk.get_isolation_scope()
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
scope.set_client(marker_value)
return scope

if isinstance(marker_value, sentry_sdk.Scope):
# If a Scope instance is provided, use the client from it
scope = sentry_sdk.get_isolation_scope()
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
scope.set_client(marker_value.client)
return marker_value

Expand Down
14 changes: 13 additions & 1 deletion pytest_sentry/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ def _with_isolation_scope(wrapped, instance, args, kwargs):
else:
with sentry_sdk.use_isolation_scope(isolation_scope):
gen = wrapped(*args, **kwargs)
yield from gen

while True:
try:
with sentry_sdk.use_isolation_scope(isolation_scope):
chunk = next(gen)

y = yield chunk

with sentry_sdk.use_isolation_scope(isolation_scope):
gen.send(y)

except StopIteration:
break

def inner(f):
return pytest.hookimpl(hookwrapper=True, **kwargs)(_with_isolation_scope(f))
Expand Down
5 changes: 0 additions & 5 deletions tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ def test_basic():
_assert_right_scopes()


def test_correct_span():
# Ensure that we are within a root span (started by the pytest_runtest_call hook)
assert sentry_sdk.get_current_scope().span is not None


class TestSimpleClass(object):
def setup_method(self):
_assert_right_scopes()
Expand Down