Skip to content

Commit 242871c

Browse files
committed
README: add a new example and fix the old one
1 parent 2a1d1d4 commit 242871c

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

README.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)