Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upcannot perform operation: another operation is in progress when running from pytest #713
Comments
|
Seams like applying this fixes problem #539 (comment) Also still have a feeling that doing something wrong here if I need such workarounds... Seams to be pretty common task to wrap Gino calls in unittests, is there any other points in documentation about it? |
|
Hey thanks for trying GINO out and sorry for the late reply! Let me take a look at this one. |
|
Here's a modified self-contained version of your example that works with pytest-aiohttp: import pytest
from aiohttp import web
from gino.ext.aiohttp import Gino
DSN = "postgresql:///t713"
db = Gino()
app = web.Application(middlewares=[db])
db.init_app(app, dict(dsn=DSN))
class User(db.Model):
__tablename__ = "users"
email = db.Column(db.String)
async def register(request):
existing_user = await User.query.where(User.email == "1").gino.first()
return web.Response(text="Hello, world")
app.add_routes([web.get("/users/", register)])
if __name__ == "__main__":
import asyncio
asyncio.get_event_loop().run_until_complete(db.set_bind(DSN))
asyncio.get_event_loop().run_until_complete(db.gino.create_all())
asyncio.get_event_loop().run_until_complete(db.pop_bind().close())
web.run_app(app)
@pytest.fixture
def cli(loop, aiohttp_client):
return loop.run_until_complete(aiohttp_client(app))
async def test_hello(cli):
resp = await cli.get("/users/")
assert resp.status == 200
text = await resp.text()
assert "Hello, world" in textAnd I think the tests in gino-aiohttp examples are also working. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Description
Hi Guys, thanks for hardwork, we were dreaming about async ORM for a while, were using sqla TPEs and other workaround, and now it is here!
But from first day we faced with issue which seams to be very unclear.
I have 1 REST endpoint on aiohttp
If I do
In side pytest file on root level it is ok. But once I call it from pytest function I got:
I am even not trying to perfrom another operation. If we add print to register method - it called once