Skip to content

Commit

Permalink
fix: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos committed Sep 14, 2024
1 parent c363a14 commit 06710cc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion peewee_async/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def aio_execute_sql(
params: Optional[List[Any]] = None,
fetch_results: Optional[FetchResults] = None
) -> Any:
__log__.debug(sql, params)
__log__.debug((sql, params))
with peewee.__exception_wrapper__:
async with self.aio_connection() as connection:
async with connection.cursor() as cursor:
Expand Down
1 change: 0 additions & 1 deletion tests/aio_model/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async def test_count_query(db: AioDatabase) -> None:
for num in range(5):
await IntegerTestModel.aio_create(num=num)
count = await IntegerTestModel.select().limit(3).aio_count()
print(type(count))
assert count == 3


Expand Down
19 changes: 16 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import asyncio
import logging
from typing import AsyncGenerator, Generator

import pytest
from peewee import sort_models

from peewee_async.databases import AioDatabase
from peewee_async.utils import aiopg, aiomysql
from tests.db_config import DB_CLASSES, DB_DEFAULTS
from tests.models import ALL_MODELS
from peewee_async.utils import aiopg, aiomysql


@pytest.fixture
def enable_debug_log_level() -> Generator[None, None, None]:
logger = logging.getLogger('peewee.async')
handler = logging.StreamHandler()
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

yield

logger.removeHandler(handler)
logger.setLevel(logging.INFO)



@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -64,5 +79,3 @@ async def db(request: pytest.FixtureRequest) -> AsyncGenerator[AioDatabase, None
dbs_all = pytest.mark.parametrize(
"db", PG_DBS + MYSQL_DBS, indirect=["db"]
)


11 changes: 11 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import peewee
import pytest
from pytest import LogCaptureFixture

from peewee_async.databases import AioDatabase
from tests.conftest import dbs_all
Expand Down Expand Up @@ -91,3 +92,13 @@ async def test_allow_sync_is_reverted_for_exc(db: AioDatabase) -> None:
except peewee.IntegrityError:
pass
assert db._allow_sync is False


@dbs_all
async def test_logging(db: AioDatabase, caplog: LogCaptureFixture, enable_debug_log_level: None) -> None:

await TestModel.aio_create(text="Test 1")

assert 'INSERT INTO' in caplog.text
assert 'testmodel' in caplog.text
assert 'VALUES' in caplog.text

0 comments on commit 06710cc

Please sign in to comment.