Flask 的测试客户端到底能做什么?cookie 怎么处理?重定向要不要跟随?怎么预置登录状态?流式响应能不能测?这篇逐项运行并打印结果。
json= → {'ctype': 'application/json', 'got': {'a': 1}} (Content-Type 由客户端自动设成 application/json)
query_string={a:[1,2], b:x} → {'a': ['1', '2'], 'b': ['x']}
URL 里已有查询串,同时传 query_string → ValueError: Query string is defined in the path and as an argument同一个客户端的下一个请求读到的 cookie: 1 use_cookies=False 的客户端: none 两个客户端互不影响: none
默认 → 302 Location: /home
follow_redirects=True → 200 {'host': 'localhost', 'ip': '127.0.0.1', 'scheme': 'http', 'user': 'ann'} | r.history 长度: 1预置 session 后访问 /home → preset
environ_overrides REMOTE_ADDR → 203.0.113.7 base_url='https://example.test' → https example.test 默认的主机名与地址: localhost 127.0.0.1
普通调用之后读 g.x → RuntimeError: Working outside of application context.
with client: 里请求之后读 request.args.get("z") → 9 | g.x → in-request普通 get: '0\n1\n2\n' buffered=False: [b'0\n', b'1\n', b'2\n'] (迭代器,可以逐块消费)