@@ -158,6 +158,7 @@ def test_has_trace_if_performance_enabled(sentry_init, client, capture_events):
158158 )
159159 events = capture_events ()
160160 response = client .head (reverse ("view_exc_with_msg" ))
161+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
161162 response .close ()
162163
163164 (msg_event , error_event , transaction_event ) = events
@@ -217,6 +218,7 @@ def test_trace_from_headers_if_performance_enabled(sentry_init, client, capture_
217218 response = client .head (
218219 reverse ("view_exc_with_msg" ), headers = {"sentry-trace" : sentry_trace_header }
219220 )
221+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
220222 response .close ()
221223
222224 (msg_event , error_event , transaction_event ) = events
@@ -1189,6 +1191,7 @@ def test_span_origin(sentry_init, client, capture_events):
11891191 events = capture_events ()
11901192
11911193 response = client .get (reverse ("view_with_signal" ))
1194+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
11921195 response .close ()
11931196
11941197 (transaction ,) = events
@@ -1214,9 +1217,17 @@ def test_transaction_http_method_default(sentry_init, client, capture_events):
12141217 )
12151218 events = capture_events ()
12161219
1217- client .get ("/nomessage" ).close ()
1218- client .options ("/nomessage" ).close ()
1219- client .head ("/nomessage" ).close ()
1220+ response = client .get ("/nomessage" )
1221+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
1222+ response .close ()
1223+
1224+ response = client .options ("/nomessage" )
1225+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
1226+ response .close ()
1227+
1228+ response = client .head ("/nomessage" )
1229+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
1230+ response .close ()
12201231
12211232 (event ,) = events
12221233
@@ -1238,9 +1249,18 @@ def test_transaction_http_method_custom(sentry_init, client, capture_events):
12381249 )
12391250 events = capture_events ()
12401251
1241- client .get ("/nomessage" ).close ()
1242- client .options ("/nomessage" ).close ()
1243- client .head ("/nomessage" ).close ()
1252+ response = client .get ("/nomessage" )
1253+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
1254+ response .close ()
1255+
1256+ response = client .options ("/nomessage" )
1257+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
1258+ response .close ()
1259+
1260+ response = client .head ("/nomessage" )
1261+ # Close the response to ensure the WSGI cycle is complete and the transaction is finished
1262+ response .close ()
1263+
12441264
12451265 assert len (events ) == 2
12461266
0 commit comments