42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
# 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
|