Files
test-litestar-addressbook/tests/test_general.py
2023-09-20 21:25:05 +02:00

32 lines
968 B
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
from sqlalchemy.ext.asyncio import AsyncSession
from tests.factories.city_factory import CityFactory
class TestGeneral:
@pytest.fixture(scope="function", autouse=True)
def setup_class(self, db_session: AsyncSession):
self.db_session = db_session
@pytest.mark.asyncio
async def test_get_cities(self):
city_1 = await CityFactory.create()
city_2 = await CityFactory.create()
city_3 = await CityFactory.create()
city_4 = await CityFactory.create()
city_5 = await CityFactory.create()
stmt = text("select * from cities")
result = await self.db_session.execute(stmt)
print("#" * 100)
for c in result:
print(c)
print("#" * 100)
assert True