Skip to content
Closed
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
12 changes: 11 additions & 1 deletion kepler/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unit = [
]
# Dependencies of integration tests
integration = [
"jubilant>=1.8,<2",
"jubilant==1.12.0",
"pytest",
"pytest-jubilant>=2.0.1,<3",
"PyYAML",
Expand All @@ -59,6 +59,16 @@ show_missing = true
minversion = "6.0"
log_cli_level = "INFO"

# Retain INFO logs in the "Captured log call" section when run interactively.
# Otherwise, that section will have DEBUG logs (coming from log_file_level).
log_level = "INFO"

log_cli_format = "%(levelname)s %(name)s %(message)s"

log_file_level = "DEBUG"
log_file_format = "%(asctime)s %(levelname)s %(name)s %(message)s"
log_file_date_format = "%Y-%m-%dT%H:%M:%SZ"

# Linting tools configuration
[tool.ruff]
line-length = 99
Expand Down
40 changes: 40 additions & 0 deletions kepler/tests/integration/test_log_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2026 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Differential test: does log_level = INFO filter DEBUG logs from caplog?

The same test runs in two charms. One charm (kepler) has log_level = "INFO"
set in pyproject.toml alongside log_file_level = "DEBUG"; the other (kosmos)
has only log_file_level = "DEBUG". The test emits a DEBUG log via the
jubilant.wait logger and asserts it appears in caplog records.

Without log_level, pytest's log_file_level = DEBUG lowers the root logger to
DEBUG and the caplog handler (left at NOTSET) captures DEBUG records. With
log_level = INFO, the caplog handler is raised to INFO and filters them out.
"""

import logging

import pytest

_WAIT_LOGGER = logging.getLogger("jubilant.wait")
_DEBUG_MESSAGE = "differential test: debug log from jubilant.wait"


@pytest.mark.xfail(strict=True, reason="log_level=INFO filters DEBUG from caplog")
def test_debug_log_from_jubilant_wait_is_captured(caplog: pytest.LogCaptureFixture):
"""Assert that a DEBUG log from jubilant.wait appears in caplog records."""
_WAIT_LOGGER.debug(_DEBUG_MESSAGE)
captured = [record.getMessage() for record in caplog.records]
assert _DEBUG_MESSAGE in captured
70 changes: 35 additions & 35 deletions kepler/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion kosmos/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unit = [
]
# Dependencies of integration tests
integration = [
"jubilant>=1.8,<2",
"jubilant==1.12.0",
"pytest",
"pytest-jubilant>=2.0.1,<3",
"PyYAML",
Expand All @@ -59,6 +59,12 @@ show_missing = true
minversion = "6.0"
log_cli_level = "INFO"

log_cli_format = "%(levelname)s %(name)s %(message)s"

log_file_level = "DEBUG"
log_file_format = "%(asctime)s %(levelname)s %(name)s %(message)s"
log_file_date_format = "%Y-%m-%dT%H:%M:%SZ"

# Linting tools configuration
[tool.ruff]
line-length = 99
Expand Down
39 changes: 39 additions & 0 deletions kosmos/tests/integration/test_log_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2026 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Differential test: does log_level = INFO filter DEBUG logs from caplog?

The same test runs in two charms. One charm (kepler) has log_level = "INFO"
set in pyproject.toml alongside log_file_level = "DEBUG"; the other (kosmos)
has only log_file_level = "DEBUG". The test emits a DEBUG log via the
jubilant.wait logger and asserts it appears in caplog records.

Without log_level, pytest's log_file_level = DEBUG lowers the root logger to
DEBUG and the caplog handler (left at NOTSET) captures DEBUG records. With
log_level = INFO, the caplog handler is raised to INFO and filters them out.
"""

import logging

import pytest

_WAIT_LOGGER = logging.getLogger("jubilant.wait")
_DEBUG_MESSAGE = "differential test: debug log from jubilant.wait"


def test_debug_log_from_jubilant_wait_is_captured(caplog: pytest.LogCaptureFixture):
"""Assert that a DEBUG log from jubilant.wait appears in caplog records."""
_WAIT_LOGGER.debug(_DEBUG_MESSAGE)
captured = [record.getMessage() for record in caplog.records]
assert _DEBUG_MESSAGE in captured
70 changes: 35 additions & 35 deletions kosmos/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading