Command exited with code 1. Command output: ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.2.0, pluggy-1.7.0 -- /root/telegram-saas/.venv/bin/python3 cachedir: .pytest_cache rootdir: /root/telegram-saas configfile: pyproject.toml plugins: anyio-4.16.0, asyncio-1.5.0 asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function collecting ... collected 2 items tests/unit/test_coupons_and_entitlements.py::test_coupon_validation_and_discounts PASSED [ 50%] tests/unit/test_coupons_and_entitlements.py::test_entitlement_enforcement_and_feature_gates FAILED [100%] =================================== FAILURES =================================== ________________ test_entitlement_enforcement_and_feature_gates ________________ @pytest.mark.asyncio async def test_entitlement_enforcement_and_feature_gates(): tenant_id = uuid.uuid4() async with get_db_session() as session: billing_service = BillingService(session) > await billing_service.seed_default_plans() tests/unit/test_coupons_and_entitlements.py:92: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ modules/billing/service.py:136: in seed_default_plans await self.repo.upsert_plan(plan) modules/billing/repository.py:39: in upsert_plan existing = await self.get_plan_by_id(plan.id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modules/billing/repository.py:35: in get_plan_by_id res = await self.db.execute(select(Plan).where(Plan.id == plan_id)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/ext/asyncio/session.py:652: in execute result = await greenlet_spawn( .venv/lib/python3.12/site-packages/sqlalchemy/util/concurrency.py:214: in greenlet_spawn result = context.throw(*sys.exc_info()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py:2555: in execute return self._execute_internal( .venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py:2432: in _execute_internal conn = self._connection_for_bind(bind) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py:2255: in _connection_for_bind return trans._connection_for_bind(engine, execution_options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :2: in _connection_for_bind return target(fn, self, bind, execution_options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py:137: in _go ret_value = fn(self, *arg, **kw) ^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py:1282: in _connection_for_bind conn = bind.connect() ^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py:3279: in connect return self._connection_cls(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py:154: in __init__ self._dbapi_connection = engine.raw_connection() ^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py:3303: in raw_connection return self.pool.connect() ^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py:460: in connect return _ConnectionFairy._checkout(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py:1454: in _checkout with util.safe_reraise(): .venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py:166: in __exit__ raise exc_value.with_traceback(exc_tb) .venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py:1392: in _checkout result = pool._dialect._do_ping_w_event( .venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py:968: in _do_ping_w_event return self.do_ping(dbapi_connection) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:1223: in do_ping dbapi_connection.ping() .venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:879: in ping self._handle_exception(error) .venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:862: in _handle_exception super()._handle_exception(error) .venv/lib/python3.12/site-packages/sqlalchemy/connectors/asyncio.py:412: in _handle_exception self._handle_exception_no_connection(self.dbapi, error) .venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:856: in _handle_exception_no_connection super()._handle_exception_no_connection(dbapi, error) .venv/lib/python3.12/site-packages/sqlalchemy/connectors/asyncio.py:409: in _handle_exception_no_connection raise error.with_traceback(exc_info[2]) .venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:877: in ping _ = await_(self._async_ping()) ^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/util/concurrency.py:171: in await_ return current.parent.switch(awaitable) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/util/concurrency.py:209: in greenlet_spawn value = await result ^^^^^^^^^^^^ .venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py:886: in _async_ping await tr.start() .venv/lib/python3.12/site-packages/asyncpg/transaction.py:146: in start await self._connection.execute(query) .venv/lib/python3.12/site-packages/asyncpg/connection.py:377: in execute result = await self._protocol.query(query, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E RuntimeError: Task cb=[_run_until_complete_cb() at /usr/lib/python3.12/asyncio/base_events.py:182]> got Future attached to a different loop asyncpg/protocol/protocol.pyx:341: RuntimeError ------------------------------ Captured log call ------------------------------- ERROR sqlalchemy.pool.impl.AsyncAdaptedQueuePool:base.py:389 Exception terminating connection > Traceback (most recent call last): File "asyncpg/protocol/protocol.pyx", line 585, in asyncpg.protocol.protocol.BaseProtocol.close File "asyncpg/protocol/protocol.pyx", line 677, in _drain_cancels File "asyncpg/protocol/protocol.pyx", line 624, in asyncpg.protocol.protocol.BaseProtocol._request_cancel File "/root/telegram-saas/.venv/lib/python3.12/site-packages/asyncpg/connection.py", line 1712, in _cancel_current_command self._cancellations.add(self._loop.create_task( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/asyncio/base_events.py", line 456, in create_task self._check_closed() File "/usr/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/telegram-saas/.venv/lib/python3.12/site-packages/asyncpg/connection.py", line 1536, in close await self._protocol.close(timeout) File "asyncpg/protocol/protocol.pyx", line 610, in close File "asyncpg/protocol/protocol.pyx", line 697, in asyncpg.protocol.protocol.BaseProtocol._handle_waiter_on_connection_lost File "/usr/lib/python3.12/asyncio/base_events.py", line 795, in call_soon self._check_closed() File "/usr/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/telegram-saas/.venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 370, in _close_connection self._dialect.do_terminate(connection) File "/root/telegram-saas/.venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 1190, in do_terminate dbapi_connection.terminate() File "/root/telegram-saas/.venv/lib/python3.12/site-packages/sqlalchemy/connectors/asyncio.py", line 440, in terminate await_(asyncio.shield(self._terminate_graceful_close())) File "/root/telegram-saas/.venv/lib/python3.12/site-packages/sqlalchemy/util/concurrency.py", line 171, in await_ return current.parent.switch(awaitable) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/telegram-saas/.venv/lib/python3.12/site-packages/sqlalchemy/util/concurrency.py", line 209, in greenlet_spawn value = await result ^^^^^^^^^^^^ File "/root/telegram-saas/.venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 955, in _terminate_graceful_close await self._connection.close(timeout=2) File "/root/telegram-saas/.venv/lib/python3.12/site-packages/asyncpg/connection.py", line 1539, in close self._abort() File "/root/telegram-saas/.venv/lib/python3.12/site-packages/asyncpg/connection.py", line 1600, in _abort self._protocol.abort() File "asyncpg/protocol/protocol.pyx", line 567, in asyncpg.protocol.protocol.BaseProtocol.abort File "/usr/lib/python3.12/asyncio/sslproto.py", line 250, in abort self._force_close(None) File "/usr/lib/python3.12/asyncio/sslproto.py", line 255, in _force_close self._ssl_protocol._abort(exc) File "/usr/lib/python3.12/asyncio/sslproto.py", line 671, in _abort self._transport._force_close(exc) File "/usr/lib/python3.12/asyncio/selector_events.py", line 906, in _force_close self._loop.call_soon(self._call_connection_lost, exc) File "/usr/lib/python3.12/asyncio/base_events.py", line 795, in call_soon self._check_closed() File "/usr/lib/python3.12/asyncio/base_events.py", line 541, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed =========================== short test summary info ============================ FAILED tests/unit/test_coupons_and_entitlements.py::test_entitlement_enforcement_and_feature_gates ========================= 1 failed, 1 passed in 0.56s ========================== sys:1: RuntimeWarning: coroutine 'Connection._cancel' was never awaited