Unable to run test: get ->'NoneType' object is not callable

Hi there,
I’m porting my Sanic app from 21.6.2 to 21.12.0

When running the following test (sanic-testing==0.6.0):

# api.py
...
blueprint = Blueprint("my_service", url_prefix="/my-path")
...

# conftest.py
...
from my_project.my_project.api import blueprint
...

@pytest.fixture(scope="module")
def app_fixture():
    app = sanic.Sanic.get_app("test", force_create=True)
    app.blueprint(blueprint)
    return app

# test.py
@pytest.mark.asyncio
async def test(
   ...
    app_fixture,
):
    ...
>>> request, response = await app_fixture.asgi_client.post(
        "/my-path/to-resource", json=valid_json_request
    )

    assert response.status == 200

I got this error:

../.local/lib/python3.8/site-packages/httpx/_client.py:1807: in post
    return await self.request(
../.local/lib/python3.8/site-packages/sanic_testing/testing.py:377: in request
    response = await super().request(method, url, *args, **kwargs)
../.local/lib/python3.8/site-packages/httpx/_client.py:1481: in request
    response = await self.send(
../.local/lib/python3.8/site-packages/httpx/_client.py:1568: in send
    response = await self._send_handling_auth(
../.local/lib/python3.8/site-packages/httpx/_client.py:1604: in _send_handling_auth
    response = await self._send_handling_redirects(
../.local/lib/python3.8/site-packages/httpx/_client.py:1640: in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
../.local/lib/python3.8/site-packages/httpx/_client.py:1681: in _send_single_request
    ) = await transport.handle_async_request(
../.local/lib/python3.8/site-packages/httpx/_transports/asgi.py:157: in handle_async_request
    await self.app(scope, receive, send)
../.local/lib/python3.8/site-packages/sanic_testing/testing.py:310: in app_call_with_return
    return await asgi_app()
../.local/lib/python3.8/site-packages/sanic_testing/testing.py:304: in __call__
    await super().__call__()
../.local/lib/python3.8/site-packages/sanic/asgi.py:200: in __call__
    await self.sanic_app.handle_exception(self.request, e)
../.local/lib/python3.8/site-packages/sanic/app.py:709: in handle_exception
    await self.dispatch(
../.local/lib/python3.8/site-packages/sanic/signals.py:163: in dispatch
    return await dispatch
../.local/lib/python3.8/site-packages/sanic/signals.py:111: in _dispatch
    group, handlers, params = self.get(event, condition=condition)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sanic.signals.SignalRouter object at 0x7fe5048531f0>, event = 'http.lifecycle.exception', condition = None

    def get(  # type: ignore
        self,
        event: str,
        condition: Optional[Dict[str, str]] = None,
    ):
        extra = condition or {}
        try:
>           group, param_basket = self.find_route(
                f".{event}",
                self.DEFAULT_METHOD,
                self,
                {"__params__": {}, "__matches__": {}},
                extra=extra,
            )
E           TypeError: 'NoneType' object is not callable

Any ideas on what’s going on?

Sorry for the delay.

Please update your sanic-testing version and the issue should go away.

1 Like