Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent log spill in CI tests #670

Merged
merged 2 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/logging/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
import asyncio

import pytest

from kopf.engines.posting import event_queue_loop_var, event_queue_var


@pytest.fixture(autouse=True)
def _caplog_all_levels(caplog):
caplog.set_level(0)


@pytest.fixture(autouse=True)
def event_queue_loop(event_loop):
token = event_queue_loop_var.set(event_loop)
try:
yield event_loop
finally:
event_queue_loop_var.reset(token)


@pytest.fixture(autouse=True)
def event_queue():
queue = asyncio.Queue()
token = event_queue_var.set(queue)
try:
yield queue
finally:
event_queue_var.reset(token)
3 changes: 3 additions & 0 deletions tests/logging/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def _clear_own_handlers():
if not isinstance(handler, logging.StreamHandler) or
not isinstance(handler.formatter, ObjectFormatter)
]
original_handlers = logger.handlers[:]
yield
logger.handlers[:] = original_handlers


def _get_own_handlers(logger: logging.Logger) -> Collection[logging.Handler]:
Expand Down
15 changes: 10 additions & 5 deletions tests/logging/test_loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
from kopf.structs.bodies import Body


# Async -- to make the log enqueueing loop running.
@pytest.mark.parametrize('cls', [ObjectLogger, LocalObjectLogger])
def test_mandatory_body(cls, settings, caplog):
async def test_mandatory_body(cls, settings, caplog):
with pytest.raises(TypeError):
cls(settings=settings)


# Async -- to make the log enqueueing loop running.
@pytest.mark.parametrize('cls', [ObjectLogger, LocalObjectLogger])
def test_mandatory_settings(cls, settings, caplog):
async def test_mandatory_settings(cls, settings, caplog):
with pytest.raises(TypeError):
cls(body=Body({}))


# Async -- to make the log enqueueing loop running.
@pytest.mark.parametrize('cls', [ObjectLogger, LocalObjectLogger])
def test_extras_from_metadata(cls, settings, caplog):
async def test_extras_from_metadata(cls, settings, caplog):
body = Body({
'kind': 'kind1',
'apiVersion': 'api1/v1',
Expand All @@ -38,8 +41,9 @@ def test_extras_from_metadata(cls, settings, caplog):
}


# Async -- to make the log enqueueing loop running.
@pytest.mark.parametrize('cls', [ObjectLogger])
def test_k8s_posting_enabled_in_a_regular_logger(cls, settings, caplog):
async def test_k8s_posting_enabled_in_a_regular_logger(cls, settings, caplog):
body = Body({})

logger = cls(body=body, settings=settings)
Expand All @@ -50,8 +54,9 @@ def test_k8s_posting_enabled_in_a_regular_logger(cls, settings, caplog):
assert caplog.records[0].k8s_skip is False


# Async -- to make the log enqueueing loop running.
@pytest.mark.parametrize('cls', [LocalObjectLogger])
def test_k8s_posting_disabled_in_a_local_logger(cls, settings, caplog):
async def test_k8s_posting_disabled_in_a_local_logger(cls, settings, caplog):
body = Body({})

logger = cls(body=body, settings=settings)
Expand Down