Skip to content

Instantly share code, notes, and snippets.

@olivierphi
Created December 2, 2019 13:24
Show Gist options
  • Save olivierphi/c75b4a24c66a3cf450f9aed70b93b507 to your computer and use it in GitHub Desktop.
Save olivierphi/c75b4a24c66a3cf450f9aed70b93b507 to your computer and use it in GitHub Desktop.
a Black bug illustration (19.10b0)
import asyncio
import aiohttp
from _pytest.monkeypatch import MonkeyPatch
from app import test_utils
async def test_ping_1(
aiohttp_client: aiohttp.test_utils.TestClient,
loop: asyncio.AbstractEventLoop,
monkeypatch: MonkeyPatch,
):
test_cases = (
# test_input, expected
({"http_method": "HEAD"}, {"status": 204}),
({"http_method": "GET"}, {"status": 204}),
({"http_method": "POST"}, {"status": 405}),
)
# fmt: off
async with \
test_utils.ctx_test_config(monkeypatch=monkeypatch), \
test_utils.ctx_mqtt_broker(loop=loop, monkeypatch=monkeypatch), \
test_utils.ctx_app(loop=loop) as app \
:
# fmt: on
client = await aiohttp_client(app)
for (test_input, expected) in test_cases:
resp = await client.request(test_input["http_method"], "/ping")
assert resp.status == expected["status"]
# N.B. exact same function than `test_ping_1`, just there to
# illustrate the fact than Black "thinks" that `test_ping_2` is inside `test_ping_1`
async def test_ping_2(
aiohttp_client: aiohttp.test_utils.TestClient,
loop: asyncio.AbstractEventLoop,
monkeypatch: MonkeyPatch,
):
test_cases = (
# test_input, expected
({"http_method": "HEAD"}, {"status": 204}),
({"http_method": "GET"}, {"status": 204}),
({"http_method": "POST"}, {"status": 405}),
)
# fmt: off
async with \
test_utils.ctx_test_config(monkeypatch=monkeypatch), \
test_utils.ctx_mqtt_broker(loop=loop, monkeypatch=monkeypatch), \
test_utils.ctx_app(loop=loop) as app \
:
# fmt: on
client = await aiohttp_client(app)
for (test_input, expected) in test_cases:
resp = await client.request(test_input["http_method"], "/ping")
assert resp.status == expected["status"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment