Skip to content

Commit cf873ff

Browse files
csernazsHayaoSuzuki
andcommitted
doc: improve documentation by preferring check() method over check_assertions()
Co-authored-by: Hayao <hayao_s@tokyo-gas.co.jp>
1 parent 83d9f9f commit cf873ff

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

doc/tutorial.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ unhandled and in the end the test will be failed.
419419

420420
In some cases, however, you want to make sure that everything is ok so far,
421421
and raise AssertionError when something is not good. Call the
422-
``check_assertions()`` method of the httpserver object, and this will look at
422+
``check()`` method of the httpserver object, and this will look at
423423
the server's internal state (which is running in the other thread) and if
424424
there's something not right (such as the order of the requests not matching,
425425
or there was a non-matching request), it will raise an AssertionError and
@@ -434,7 +434,7 @@ your test will properly fail:
434434
requests.get(httpserver.url_for("/foobaz"))
435435
requests.get(httpserver.url_for("/foobar")) # gets 500
436436
437-
httpserver.check_assertions() # this will raise AssertionError and make the test failing
437+
httpserver.check() # this will raise AssertionError and make the test failing
438438
439439
This will also produce a (hopefully) helpful description about what went wrong::
440440

@@ -450,10 +450,10 @@ This will also produce a (hopefully) helpful description about what went wrong::
450450
E none
451451

452452

453-
Calling ``check_assertions()`` for all tests
453+
Calling ``check()`` for all tests
454454
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
455455

456-
Sometimes you want to see the informative message made by ``check_assertions()`` if
456+
Sometimes you want to see the informative message made by ``check()`` if
457457
your test failed.
458458

459459
In such case you can implement a new fixture or override the behavior:
@@ -471,7 +471,7 @@ In such case you can implement a new fixture or override the behavior:
471471
@pytest.fixture
472472
def httpserver(httpserver: HTTPServer) -> Iterable[HTTPServer]:
473473
yield httpserver
474-
httpserver.check_assertions() # this will raise AssertionError and make the test failing
474+
httpserver.check() # this will raise AssertionError and make the test failing
475475
476476
477477
def test_client(httpserver: HTTPServer):
@@ -520,7 +520,7 @@ Debugging
520520
~~~~~~~~~
521521

522522
If you having multiple requests for the server, adding the call to
523-
``check_assertions()`` may to debug as it will make the test failed as
523+
``check()`` may help to debug as it will make the test failed as
524524
soon as possible.
525525

526526
.. code:: python
@@ -534,20 +534,20 @@ soon as possible.
534534
requests.get(httpserver.url_for("/bar"))
535535
requests.get(httpserver.url_for("/foobar"))
536536
537-
httpserver.check_assertions()
537+
httpserver.check()
538538
539539
In the above code, the first request (to **/foo**) is not successful (it gets
540540
http status 500), but as the response status is not checked (or any of the
541-
response), and there's no call to ``check_assertions()``, the test continues the
541+
response), and there's no call to ``check()``, the test continues the
542542
running. It gets through the **/bar** request, which is also not successful
543543
(and gets http status 500 also like the first one), then goes the last request
544544
which is successful (as there's a handler defined for it)
545545

546-
In the end, when checking the check_assertions() raise the error for the first
546+
In the end, when checking the check() raise the error for the first
547547
request, but it is a bit late: figuring out the request which caused the problem
548548
could be troublesome. Also, it will report the problem for the first request only.
549549

550-
Adding more call of ``check_assertions()`` will help.
550+
Adding more call of ``check()`` will help.
551551

552552

553553
.. code:: python
@@ -558,13 +558,13 @@ Adding more call of ``check_assertions()`` will help.
558558
def test_json_client(httpserver: HTTPServer):
559559
httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"})
560560
requests.get(httpserver.url_for("/foo"))
561-
httpserver.check_assertions()
561+
httpserver.check()
562562
563563
requests.get(httpserver.url_for("/bar"))
564-
httpserver.check_assertions()
564+
httpserver.check()
565565
566566
requests.get(httpserver.url_for("/foobar"))
567-
httpserver.check_assertions()
567+
httpserver.check()
568568
569569
570570
In the above code, the test will fail after the first request.

tests/examples/test_example_blocking_httpserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def httpserver():
2222
# this is to check if the client has made any request where no
2323
# `assert_request` was called on it from the test
2424

25-
server.check_assertions()
25+
server.check()
2626
server.clear()
2727

2828

tests/examples/test_howto_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@pytest.mark.xfail
8-
def test_check_assertions(httpserver: HTTPServer):
8+
def test_check(httpserver: HTTPServer):
99
def handler(_):
1010
assert 1 == 2
1111

0 commit comments

Comments
 (0)