Skip to content

Commit

Permalink
* fix: fix logging backported 06710cc
Browse files Browse the repository at this point in the history
  • Loading branch information
strizhechenko authored Oct 15, 2024
1 parent d20b6c4 commit 9ae7a8c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
max-parallel: 4
matrix:
Expand Down
2 changes: 1 addition & 1 deletion peewee_async/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def aio_connection(self) -> ConnectionContextManager:
return ConnectionContextManager(self.pool_backend)

async def aio_execute_sql(self, sql: str, params=None, fetch_results=None):
__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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "peewee-async"
version = "0.12.0"
version = "0.12.2"
description = "Asynchronous interface for peewee ORM powered by asyncio."
authors = ["Alexey Kinev <[email protected]>", "Gorshkov Nikolay(contributor) <[email protected]>"]
readme = "README.md"
Expand Down
18 changes: 15 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import logging
from typing import Generator

import pytest
from peewee import sort_models
Expand All @@ -8,6 +10,19 @@
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)
def event_loop():
loop = asyncio.get_event_loop_policy().new_event_loop()
Expand Down Expand Up @@ -59,6 +74,3 @@ async def db(request):
dbs_all = pytest.mark.parametrize(
"db", PG_DBS + MYSQL_DBS, indirect=["db"]
)



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

import peewee
import pytest
from pytest import LogCaptureFixture

from peewee_async.databases import AioDatabase
from tests.conftest import dbs_all
from tests.db_config import DB_CLASSES, DB_DEFAULTS
from tests.models import TestModel, CompositeTestModel
Expand Down Expand Up @@ -89,3 +91,13 @@ async def test_allow_sync_is_reverted_for_exc(db):
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 9ae7a8c

Please sign in to comment.