diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index c2ee22800..dc07367fd 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -4411,8 +4411,6 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase): self.assert_in('Starting repository check', output) self.assert_in('Starting archive consistency check', output) self.assert_in('Checking segments', output) - # reset logging to new process default to avoid need for fork=True on next check - logging.getLogger('borg.output.progress').setLevel(logging.NOTSET) output = self.cmd('check', '-v', '--repository-only', self.repository_location, exit_code=0) self.assert_in('Starting repository check', output) self.assert_not_in('Starting archive consistency check', output) diff --git a/src/borg/testsuite/conftest.py b/src/borg/testsuite/conftest.py index bc40f33b7..12070964c 100644 --- a/src/borg/testsuite/conftest.py +++ b/src/borg/testsuite/conftest.py @@ -1,3 +1,4 @@ +import logging import os import pytest @@ -26,6 +27,23 @@ from borg.testsuite import are_symlinks_supported, are_hardlinks_supported, is_u from borg.testsuite.platform import fakeroot_detected # noqa: E402 +@pytest.fixture(autouse=True) +def reset_progress_logger(): + # ProgressIndicatorBase installs a handler on the process-global + # 'borg.output.progress' logger and only removes it in __del__, and in-process + # (fork=False) command execution leaves this logger at level INFO / propagate=False. + # This state leaks across tests and makes the progress tests flaky (the progress + # output ends up in the logging system instead of on the stderr captured by capfd). + # Reset it after each test to keep tests isolated. + yield + logger = logging.getLogger('borg.output.progress') + for handler in logger.handlers[:]: + logger.removeHandler(handler) + handler.close() + logger.setLevel(logging.NOTSET) + logger.propagate = True + + @pytest.fixture(autouse=True) def clean_env(tmpdir_factory, monkeypatch): # avoid that we access / modify the user's normal .config / .cache directory: