@@ -80,27 +80,38 @@ def raise_for_status_fixture(httpserver):
80
80
81
81
82
82
@run_in_pyodide
83
- async def test_pyfetch_raise_for_status (selenium , raise_for_status_fixture ):
83
+ async def test_pyfetch_raise_for_status_does_not_raise_200 (
84
+ selenium , raise_for_status_fixture
85
+ ):
84
86
import pytest
85
87
86
- from pyodide .http import pyfetch
88
+ from pyodide .http import HttpStatusError , pyfetch
87
89
88
90
resp = await pyfetch (raise_for_status_fixture ["/status_200" ])
89
91
resp .raise_for_status ()
90
92
assert await resp .string () == "Some data here!"
91
93
92
94
resp = await pyfetch (raise_for_status_fixture ["/status_404" ])
93
95
with pytest .raises (
94
- OSError , match = "404 Client Error: NOT FOUND for url: .*/status_404"
95
- ):
96
+ HttpStatusError , match = "404 Client Error: NOT FOUND for url: .*/status_404"
97
+ ) as error_404 :
96
98
resp .raise_for_status ()
97
99
100
+ assert error_404 .value .status == 404
101
+ assert error_404 .value .status_text == "NOT FOUND"
102
+ assert error_404 .value .url .endswith ("status_404" )
103
+
98
104
resp = await pyfetch (raise_for_status_fixture ["/status_504" ])
99
105
with pytest .raises (
100
- OSError , match = "504 Server Error: GATEWAY TIMEOUT for url: .*/status_504"
101
- ):
106
+ HttpStatusError ,
107
+ match = "504 Server Error: GATEWAY TIMEOUT for url: .*/status_504" ,
108
+ ) as error_504 :
102
109
resp .raise_for_status ()
103
110
111
+ assert error_504 .value .status == 504
112
+ assert error_504 .value .status_text == "GATEWAY TIMEOUT"
113
+ assert error_504 .value .url .endswith ("status_504" )
114
+
104
115
105
116
@run_in_pyodide
106
117
async def test_pyfetch_unpack_archive (selenium ):
0 commit comments