File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,11 +15,23 @@ Example
1515
1616.. code-block :: python
1717
18- def test_my_client (server ): # server is a pytest fixture which starts the server
18+ def test_my_client (httpserver ): # httpserver is a pytest fixture which starts the server
1919 # set up the server to serve /foobar with the json
20- server.expect_request(" /foobar" ).respond_with_json({" foo" : " bar" })
21- # check sthat it is served
22- assert requests.get(server.url_for(" /foobar" )).json() == {' foo' : ' bar' }
20+ httpserver.expect_request(" /foobar" ).respond_with_json({" foo" : " bar" })
21+ # check that the request is served
22+ assert requests.get(httpserver.url_for(" /foobar" )).json() == {' foo' : ' bar' }
23+
24+
25+ You can also use the library without pytest. There's a with statement to ensure that the server is stopped.
26+
27+
28+ .. code-block :: python
29+
30+ with HTTPServer() as httpserver:
31+ # set up the server to serve /foobar with the json
32+ httpserver.expect_request(" /foobar" ).respond_with_json({" foo" : " bar" })
33+ # check that the request is served
34+ print (requests.get(httpserver.url_for(" /foobar" )).json())
2335
2436
2537 Features
You can’t perform that action at this time.
0 commit comments