yunstanford / pytest-sanic

a Pytest Plugin for Sanic.
http://pytest-sanic.readthedocs.io/en/latest
Apache License 2.0
136 stars 21 forks source link

Upgrade to pytest-sanic 1.7.1 and sanic 21.3.4 failed with "sanic_routing.exceptions.FinalizationError: Cannot finalize router more than once." #53

Open xiaoxiper opened 3 years ago

xiaoxiper commented 3 years ago

Hi! I use Blueprint groups, it was ok when I used sanic 20.x with pytest-sanic 1.7.0. But when I upgraded, I encountered the following:

    @pytest.fixture
    def test_cli(loop, app, sanic_client):
>       return loop.run_until_complete(sanic_client(app))

tests/api/base.py:21:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
uvloop/loop.pyx:1456: in uvloop.loop.Loop.run_until_complete
    ???
.venv/lib/python3.8/site-packages/pytest_sanic/plugin.py:203: in create_client
    await client.start_server()
.venv/lib/python3.8/site-packages/pytest_sanic/utils.py:227: in start_server
    await self._server.start_server()
.venv/lib/python3.8/site-packages/pytest_sanic/utils.py:104: in start_server
    await trigger_events(self.before_server_start, self.loop)
.venv/lib/python3.8/site-packages/pytest_sanic/utils.py:30: in trigger_events
    await result
.venv/lib/python3.8/site-packages/sanic/app.py:1285: in finalize
    raise e  # noqa
.venv/lib/python3.8/site-packages/sanic/app.py:1280: in finalize
    app.router.finalize()
.venv/lib/python3.8/site-packages/sanic/router.py:179: in finalize
    super().finalize(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <sanic.router.Router object at 0x112b83b20>, do_compile = True

    def finalize(self, do_compile: bool = True):
        if self.finalized:
>           raise FinalizationError("Cannot finalize router more than once.")
E           sanic_routing.exceptions.FinalizationError: Cannot finalize router more than once.
mvbrn commented 3 years ago

i have the same thing, any workarounds?

michel-rodrigues commented 3 years ago

I have the same problem

yunstanford commented 3 years ago

any sample code for me to reproduce ?

Tried with one simple test (https://github.com/yunstanford/pytest-sanic/commit/e76ddeb656d14c0014399a0b8bb4d85735b6153f), seems working fine.