Basic testing infrastructure

This commit is contained in:
Eden Kirin
2023-09-20 09:56:52 +02:00
parent f57c4d4491
commit 6109630ed1
12 changed files with 451 additions and 22 deletions

41
tests/test_general.py Normal file
View File

@ -0,0 +1,41 @@
# A Guide To Database Unit Testing with Pytest and SQLAlchemy
# https://coderpad.io/blog/development/a-guide-to-database-unit-testing-with-pytest-and-sqlalchemy/
import pytest
from sqlalchemy import text, event
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from app.domain.city import City
from app.lib import settings
from app.lib.sqlalchemy_plugin import engine
import pytest
import pytest_asyncio
import sqlalchemy
from sqlalchemy.ext.asyncio import (
AsyncSession,
create_async_engine,
async_scoped_session,
AsyncConnection,
)
class TestGeneral:
@pytest.fixture(scope="function", autouse=True)
def setup_class(self, db_session):
self.db_session = db_session
# async def teardown_class(self):
# await self.session.rollback()
# await self.session.close()
@pytest.mark.asyncio
async def test_bla(self):
stmt = text("select * from cities")
result = await self.db_session.execute(stmt)
print("#"*100)
for c in result:
print(c)
print("#"*100)
assert True