File: example.py

package info (click to toggle)
pytest-httpserver 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: python: 2,382; makefile: 77; sh: 21
file content (16 lines) | stat: -rwxr-xr-x 391 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!.venv/bin/python3

import urllib.error
import urllib.request

from pytest_httpserver import HTTPServer

server = HTTPServer(port=4000)
server.expect_request("/foobar").respond_with_json({"foo": "bar"})
server.start()
try:
    print(urllib.request.urlopen("http://localhost:4000/foobar?name=John%20Smith&age=123").read())
except urllib.error.HTTPError as err:
    print(err)

server.stop()