ITADN

pytest 9.1.0 ask wrong formatting on logging module

#14603Openvallsv 创建于 2026-06-15
status: needs information
V
vallsvcommented
Hi, We have a weird CI failure in our project related to pytest update to 9.1.0. Our test check a `logging` handle in the case a requested log don't have the right amount of parameters. ``` logging.error("%s", 1, 3, 1, 2) ``` It sounds like the behavior of the `logging` module is somehow patched. But actually I am not able to understand how and why there is behavior change, that is why i ask if you have some ideas. # pytest <9.1.0 ``` platform linux -- Python 3.11.15, pytest-9.0.3, pluggy-1.6.0 rootdir: /nobackup/lvalls1/valls/workspace/bliss.git/flint configfile: pyproject.toml plugins: xvfb-3.1.1, rerunfailures-16.1, mock-3.15.1, cov-7.1.0, profiling-1.8.1 collected 1 item flint/tests/flint/widgets/test_logging_list.py . [100%] ``` # pytest ==9.1.0 ``` platform linux -- Python 3.11.15, pytest-9.1.0, pluggy-1.6.0 rootdir: /nobackup/lvalls1/valls/workspace/bliss.git/flint configfile: pyproject.toml plugins: xvfb-3.1.1, rerunfailures-16.1, mock-3.15.1, cov-7.1.0, profiling-1.8.1 collected 1 item flint/tests/flint/widgets/test_logging_list.py F [100%] ============================================================================ FAILURES ============================================================================ _______________________________________________________________________ test_buggy_logging _______________________________________________________________________ xvfb = <pytest_xvfb.Xvfb object at 0x7f25dc392ad0>, silxTestUtils = <silx.gui.utils.testutils.TestCaseQt testMethod=runTest> loggingList = <flint.widgets.logging_list.LoggingList object at 0x7f25dc0109d0> def test_buggy_logging(xvfb, silxTestUtils, loggingList): widget = loggingList assert widget.logCount() == 0 > test_logger.warning("Two fields expected %s %f", "foo") flint/tests/flint/widgets/test_logging_list.py:66: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .pixi/envs/bliss/lib/python3.11/logging/__init__.py:1501: in warning self._log(WARNING, msg, args, **kwargs) .pixi/envs/bliss/lib/python3.11/logging/__init__.py:1634: in _log self.handle(record) .pixi/envs/bliss/lib/python3.11/logging/__init__.py:1644: in handle self.callHandlers(record) .pixi/envs/bliss/lib/python3.11/logging/__init__.py:1706: in callHandlers hdlr.handle(record) .pixi/envs/bliss/lib/python3.11/logging/__init__.py:978: in handle self.emit(record) .pixi/envs/bliss/lib/python3.11/site-packages/_pytest/logging.py:399: in emit super().emit(record) .pixi/envs/bliss/lib/python3.11/logging/__init__.py:1118: in emit self.handleError(record) .pixi/envs/bliss/lib/python3.11/logging/__init__.py:1110: in emit msg = self.format(record) ^^^^^^^^^^^^^^^^^^^ .pixi/envs/bliss/lib/python3.11/logging/__init__.py:953: in format return fmt.format(record) ^^^^^^^^^^^^^^^^^^ .pixi/envs/bliss/lib/python3.11/site-packages/_pytest/logging.py:137: in format return super().format(record) ^^^^^^^^^^^^^^^^^^^^^^ .pixi/envs/bliss/lib/python3.11/logging/__init__.py:687: in format record.message = record.getMessage() ``` # `logging` behavour With python 3 (at least 3.11) there is no exception raised. ``` Python 3.11.15 | packaged by conda-forge | (main, Mar 5 2026, 16:45:40) [GCC 14.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pytest >>> import logging; logging.warning("foo %s") WARNING:root:foo %s ``` In python 2.7, such call would raise a `TypeError: not enough arguments for format string` I will check the behavior of newer python interpreter. But actually i dont have much idea why the be behaviour change. Any idea is welcome.
3 条评论