8000 Fix test_api (#3787) · getsentry/sentry-python@aa9c5ca · GitHub
[go: up one dir, main page]

Skip to content

Commit aa9c5ca

Browse files
authored
Fix test_api (#3787)
1 parent c29382d commit aa9c5ca

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,18 @@ def __eq__(self, other):
642642

643643
def __ne__(self, other):
644644
return not self.__eq__(other)
645+
646+
647+
@pytest.fixture(name="SortedBaggage")
648+
def sorted_baggage_matcher():
649+
class SortedBaggage:
650+
def __init__(self, baggage):
651+
self.baggage = baggage
652+
653+
def __eq__(self, other):
654+
return sorted(self.baggage.split(",")) == sorted(other.split(","))
655+
656+
def __ne__(self, other):
657+
return not self.__eq__(other)
658+
659+
return SortedBaggage

tests/test_api.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
get_current_span,
1010
get_traceparent,
1111
is_initialized,
12-
start_transaction,
12+
start_span,
1313
set_tags,
1414
get_global_scope,
1515
get_current_scope,
@@ -43,23 +43,23 @@ def test_get_current_span_current_scope(sentry_init):
4343

4444

4545
@pytest.mark.forked
46-
def test_get_current_span_current_scope_with_transaction(sentry_init):
46+
def test_get_current_span_current_scope_with_span(sentry_init):
4747
sentry_init()
4848

4949
assert get_current_span() is None
5050

51-
with start_transaction() as new_transaction:
52-
assert get_current_span() == new_transaction
51+
with start_span() as new_span:
52+
assert get_current_span() == new_span
5353

5454

5555
@pytest.mark.forked
5656
def test_traceparent_with_tracing_enabled(sentry_init):
5757
sentry_init(traces_sample_rate=1.0)
5858

59-
with start_transaction() as transaction:
59+
with start_span() as span:
6060
expected_traceparent = "%s-%s-1" % (
61-
transaction.trace_id,
62-
transaction.span_id,
61+
span.trace_id,
62+
span.span_id,
6363
)
6464
assert get_traceparent() == expected_traceparent
6565

@@ -77,51 +77,51 @@ def test_traceparent_with_tracing_disabled(sentry_init):
7777

7878

7979
@pytest.mark.forked
80-
def test_baggage_with_tracing_disabled(sentry_init):
80+
def test_baggage_with_tracing_disabled(sentry_init, SortedBaggage):
8181
sentry_init(release="1.0.0", environment="dev")
8282
propagation_context = get_isolation_scope()._propagation_context
8383
expected_baggage = (
8484
"sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0".format(
8585
propagation_context.trace_id
8686
)
8787
)
88-
assert get_baggage() == expected_baggage
88+
assert get_baggage() == SortedBaggage(expected_baggage)
8989

9090

9191
@pytest.mark.forked
92-
def test_baggage_with_tracing_enabled(sentry_init):
92+
def test_baggage_with_tracing_enabled(sentry_init, SortedBaggage):
9393
sentry_init(traces_sample_rate=1.0, release="1.0.0", environment="dev")
94-
with start_transaction() as transaction:
94+
with start_span() as span:
9595
expected_baggage = "sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0,sentry-sample_rate=1.0,sentry-sampled={}".format(
96-
transaction.trace_id, "true" if transaction.sampled else "false"
96+
span.trace_id, "true" if span.sampled else "false"
9797
)
98-
assert get_baggage() == expected_baggage
98+
assert get_baggage() == SortedBaggage(expected_baggage)
9999

100100

101101
@pytest.mark.forked
102102
def test_continue_trace(sentry_init):
103-
sentry_init()
103+
sentry_init(traces_sample_rate=1.0)
104104

105105
trace_id = "471a43a4192642f0b136d5159a501701"
106106
parent_span_id = "6e8f22c393e68f19"
107107
parent_sampled = 1
108-
transaction = continue_trace(
108+
109+
with continue_trace(
109110
{
110111
"sentry-trace": "{}-{}-{}".format(trace_id, parent_span_id, parent_sampled),
111112
"baggage": "sentry-trace_id=566e3688a61d4bc888951642d6f14a19",
112113
},
113-
name="some name",
114-
)
115-
with start_transaction(transaction):
116-
assert 57A7 transaction.name == "some name"
117-
118-
propagation_context = get_isolation_scope()._propagation_context
119-
assert propagation_context.trace_id == transaction.trace_id == trace_id
120-
assert propagation_context.parent_span_id == parent_span_id
121-
assert propagation_context.parent_sampled == parent_sampled
122-
assert propagation_context.dynamic_sampling_context == {
123-
"trace_id": "566e3688a61d4bc888951642d6f14a19"
124-
}
114+
):
115+
with start_span(name="some name") as span:
116+
assert span.name == "some name"
117+
118+
propagation_context = get_isolation_scope()._propagation_context
119+
assert propagation_context.trace_id == span.trace_id == trace_id
< 612E code>120+
assert propagation_context.parent_span_id == parent_span_id
121+
assert propagation_context.parent_sampled == parent_sampled
122+
assert propagation_context.dynamic_sampling_context == {
123+
"trace_id": "566e3688a61d4bc888951642d6f14a19"
124+
}
125125

126126

127127
@pytest.mark.forked

0 commit comments

Comments
 (0)
0