The error would be thrown anyway downstream, when tasks are created, but
other spurious warning might be raised too because certain tasks are not
awaited.
if not self._closed:
return
+ # Throw a RuntimeError if the pool is open outside a running loop.
+ asyncio.get_running_loop()
+
self._check_open()
# Create these objects now to attach them to the right loop.
await p.close()
asyncio.run(asyncio.wait_for(test(), timeout=2.0))
+
+
+def test_cant_create_open_outside_loop(dsn):
+ with pytest.raises(RuntimeError):
+ pool.AsyncConnectionPool(dsn, open=True)