File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -260,15 +260,9 @@ Use the router instance as decorator or context manager to patch `HTTPX` and act
260
260
import httpx
261
261
import respx
262
262
263
- from httpx import Response
264
-
265
-
266
- api_mock = respx.mock(assert_all_called = False )
267
- api_mock.route(
268
- url = " https://api.foo.bar/baz/" ,
269
- name = " baz" ,
270
- ).mock(
271
- return_value = Response(200 , json = {" name" : " baz" }),
263
+ api_mock = respx.mock(base_url = " https://api.foo.bar/" , assert_all_called = False )
264
+ api_mock.get(" /baz/" , name = " baz" ).mock(
265
+ return_value = httpx.Response(200 , json = {" name" : " baz" }),
272
266
)
273
267
...
274
268
@@ -286,6 +280,8 @@ def test_ctx_manager():
286
280
...
287
281
```
288
282
283
+ !!! tip "Catch-all"
284
+ Add a * catch-all* route last as a fallback for any non-matching request, e.g. ` api_mock.route().respond(404) ` .
289
285
!!! note "NOTE"
290
286
Named routes in a * reusable router* can be directly accessed via ` my_mock_router[<route name>] `
291
287
You can’t perform that action at this time.
0 commit comments