Skip to content

test_logging: BaseFileTest.tearDown() can leave a handler on the root logger #155423

Description

@serhiy-storchaka

BaseFileTest.tearDown() in test_logging unlinks the log files and then calls BaseTest.tearDown(), which removes the handler added by BaseTest.setUp().

If unlinking fails, BaseTest.tearDown() is not called, the handler is left on the root logger, and every following test fails in setUp() with "Unexpected handlers", hiding the original error.

The files registered by assertLogFile() are unlinked without checking that they still exist, so this happens if a test removes its own log file, for example by creating it in a temporary directory removed by a cleanup function.

No test does that now, so the bug is latent. I ran into it with an experimental change to the order in which cleanup functions are called.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions