Skip to content

Commit 3b054b6

Browse files
better testing approach
1 parent 91ec188 commit 3b054b6

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

tests/integrations/stdlib/test_httplib.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,17 @@ def test_no_request_source_if_duration_too_short(sentry_init, capture_events):
525525

526526
already_patched_putrequest = HTTPConnection.putrequest
527527

528-
def overwrite_timestamps_putrequest(self, *args, **kwargs):
529-
already_patched_putrequest(self, *args, **kwargs)
530-
span = self._sentrysdk_span
531-
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
532-
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=99999)
533-
534-
HTTPConnection.putrequest = overwrite_timestamps_putrequest
528+
class HttpConnectionWithPatchedSpan(HTTPConnection):
529+
def putrequest(self, *args, **kwargs) -> None:
530+
already_patched_putrequest(self, *args, **kwargs)
531+
span = self._sentrysdk_span # type: ignore
532+
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
533+
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=99999)
535534

536535
events = capture_events()
537536

538537
with start_transaction(name="foo"):
539-
conn = HTTPConnection("localhost", port=PORT)
538+
conn = HttpConnectionWithPatchedSpan("localhost", port=PORT)
540539
conn.request("GET", "/foo")
541540
conn.getresponse()
542541

@@ -555,25 +554,24 @@ def overwrite_timestamps_putrequest(self, *args, **kwargs):
555554

556555
def test_request_source_if_duration_over_threshold(sentry_init, capture_events):
557556
sentry_init(
558-
enable_tracing=True,
557+
traces_sample_rate=1.0,
559558
enable_db_query_source=True,
560559
db_query_source_threshold_ms=100,
561560
)
562561

563562
already_patched_putrequest = HTTPConnection.putrequest
564563

565-
def overwrite_timestamps_putrequest(self, *args, **kwargs):
566-
already_patched_putrequest(self, *args, **kwargs)
567-
span = self._sentrysdk_span
568-
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
569-
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=100001)
570-
571-
HTTPConnection.putrequest = overwrite_timestamps_putrequest
564+
class HttpConnectionWithPatchedSpan(HTTPConnection):
565+
def putrequest(self, *args, **kwargs) -> None:
566+
already_patched_putrequest(self, *args, **kwargs)
567+
span = self._sentrysdk_span # type: ignore
568+
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
569+
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=100001)
572570

573571
events = capture_events()
574572

575573
with start_transaction(name="foo"):
576-
conn = HTTPConnection("localhost", port=PORT)
574+
conn = HttpConnectionWithPatchedSpan("localhost", port=PORT)
577575
conn.request("GET", "/foo")
578576
conn.getresponse()
579577

0 commit comments

Comments
 (0)