1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
"""
This example is used in the README.md
To run this example, first `pip install httpx`
This example is NOT tested by the test suite.
"""
import httpx
from pytest_check import check
def test_httpx_get():
r = httpx.get("https://www.example.org/")
# bail if bad status code
assert r.status_code == 200
# but if we get here
# no need to stop on any failure
with check:
assert r.is_redirect is False
with check:
assert r.encoding == "utf-8"
with check:
assert "Example Domain" in r.text
def test_httpx_get_with_helpers():
r = httpx.get("https://www.example.org/")
assert r.status_code == 200
check.is_false(r.is_redirect)
check.equal(r.encoding, "utf-8")
check.is_in("Example Domain", r.text)
|