From 879015c0b1c42ee95a88fbda92bbaa1e860e69f3 Mon Sep 17 00:00:00 2001 From: Alex <122354532+sinnwise@users.noreply.github.com> Date: Sun, 19 Nov 2023 08:53:58 +0000 Subject: [PATCH] Update `testing.md` with fixed code for pytest blacksheep testing (#29) This problem seems to come across with 3.11, don't exactly know the circumstances in why/which this error gets reported. ``` test_test.py::test_create_and_get_todo FAILED [100%] test_test.py:4 (test_create_and_get_todo) test_client = @pytest.mark.asyncio async def test_create_and_get_todo(test_client: TestClient) -> None: > response = await test_client.get("/") E AttributeError: 'coroutine' object has no attribute 'get' test_test.py:7: AttributeError ``` --- docs/testing.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 852f278..8470c6e 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -370,6 +370,7 @@ file to include fixtures definition to arrange tests for the web application: import asyncio import pytest +import pytest_asyncio from blacksheep.testing import TestClient from server import app as app_server @@ -381,14 +382,14 @@ def event_loop(request): loop.close() -@pytest.fixture(scope="session") +@pytest_asyncio.fixture(scope="session") async def api(): await app_server.start() yield app_server await app_server.stop() -@pytest.fixture(scope="session") +@pytest_asyncio.fixture(scope="session") async def test_client(api): return TestClient(api)