Skip to content

Commit 06710cc

Browse files
committed
fix: logging
1 parent c363a14 commit 06710cc

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

peewee_async/databases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async def aio_execute_sql(
135135
params: Optional[List[Any]] = None,
136136
fetch_results: Optional[FetchResults] = None
137137
) -> Any:
138-
__log__.debug(sql, params)
138+
__log__.debug((sql, params))
139139
with peewee.__exception_wrapper__:
140140
async with self.aio_connection() as connection:
141141
async with connection.cursor() as cursor:

tests/aio_model/test_shortcuts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ async def test_count_query(db: AioDatabase) -> None:
5555
for num in range(5):
5656
await IntegerTestModel.aio_create(num=num)
5757
count = await IntegerTestModel.select().limit(3).aio_count()
58-
print(type(count))
5958
assert count == 3
6059

6160

tests/conftest.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import asyncio
2+
import logging
23
from typing import AsyncGenerator, Generator
34

45
import pytest
56
from peewee import sort_models
67

78
from peewee_async.databases import AioDatabase
9+
from peewee_async.utils import aiopg, aiomysql
810
from tests.db_config import DB_CLASSES, DB_DEFAULTS
911
from tests.models import ALL_MODELS
10-
from peewee_async.utils import aiopg, aiomysql
12+
13+
14+
@pytest.fixture
15+
def enable_debug_log_level() -> Generator[None, None, None]:
16+
logger = logging.getLogger('peewee.async')
17+
handler = logging.StreamHandler()
18+
logger.addHandler(handler)
19+
logger.setLevel(logging.DEBUG)
20+
21+
yield
22+
23+
logger.removeHandler(handler)
24+
logger.setLevel(logging.INFO)
25+
1126

1227

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

tests/test_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import peewee
66
import pytest
7+
from pytest import LogCaptureFixture
78

89
from peewee_async.databases import AioDatabase
910
from tests.conftest import dbs_all
@@ -91,3 +92,13 @@ async def test_allow_sync_is_reverted_for_exc(db: AioDatabase) -> None:
9192
except peewee.IntegrityError:
9293
pass
9394
assert db._allow_sync is False
95+
96+
97+
@dbs_all
98+
async def test_logging(db: AioDatabase, caplog: LogCaptureFixture, enable_debug_log_level: None) -> None:
99+
100+
await TestModel.aio_create(text="Test 1")
101+
102+
assert 'INSERT INTO' in caplog.text
103+
assert 'testmodel' in caplog.text
104+
assert 'VALUES' in caplog.text

0 commit comments

Comments
 (0)