Skip to content

Commit b9437ab

Browse files
committed
howto: fix blocking httpserver howto
It is recommended to call check_assertions() at the end of the test run to check if there were any requests made by the client which were not handled at all. In that case the server registers that there was an error and this needs to be checked at the end.
1 parent bc3bcfa commit b9437ab

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

doc/howto.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,13 @@ Running httpserver in blocking mode
662662
In this mode, the code which is being tested (the client) is executed in a
663663
background thread, while the server events are synchronized to the main thread,
664664
so it looks like it is running in the main thread. This allows to catch the
665-
assertions occured on the server side synchronously, it is not needed to call
666-
the `check_assertions` method, assertions are raised to the main thread.
665+
assertions occured on the server side synchronously, and assertions are raised
666+
to the main thread. You need to call `check_assertions` at the end for only the
667+
unexpected requests.
667668

668-
This is an experimental feature so *pytest-httpserver* has no fixture for it.
669+
This is an experimental feature so *pytest-httpserver* has no fixture for it
670+
yet. If you find this feature useful any you have ideas or suggestions related
671+
to this, feel free to open an issue.
669672

670673
Example:
671674

tests/test_blocking_httpserver_howto.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def httpserver():
2020
if server.is_running():
2121
server.stop()
2222

23+
# this is to check if the client has made any request where no
24+
# `assert_request` was called on it from the test
25+
26+
server.check_assertions()
27+
server.clear()
28+
2329

2430
def test_simplified(httpserver: BlockingHTTPServer):
2531
def client(response_queue: Queue):

0 commit comments

Comments
 (0)