sanic-org / sanic-testing

Test clients for Sanic
https://sanic.dev/en/plugins/sanic-testing/getting-started.html
MIT License
31 stars 19 forks source link

Add reusable client tests and refactor #74

Closed hamedsh closed 5 months ago

hamedsh commented 9 months ago

In Python 3.12, its required to close the writer to stop the server. unless its hangs on wait_closed

how to reproduce: python=3.12.x

import pytest
from sanic import Sanic, response

from sanic_testing.reusable import ReusableClient

@pytest.fixture
def reusable_app():
    sanic_app = Sanic(__name__)

    @sanic_app.get("/")
    def basic(request):
        return response.text("foo")

    return sanic_app

@pytest.mark.asyncio
def test_basic_asgi_client(reusable_app):
    client = ReusableClient(reusable_app)
    with client:
        request, response = client.get("/")

        assert request.method.lower() == "get"
        assert response.body == b"foo"
        assert response.status == 200
dnikolayev commented 9 months ago

Hey @ahopkins

Sorry for asking: when could we expect the merging of this PR / releasing a new version of sanic-testing?

Thanks a lot!