def test_change_level_undoes_handler_level(pytester: Pytester) -> None:
    """Ensure that 'set_level' is undone after the end of the test (handler).

    Issue #7569. Tests the handler level specifically.
    """
    pytester.makepyfile(
        """
        import logging

        def test1(caplog):
            assert caplog.handler.level == 0
            caplog.set_level(9999)
            caplog.set_level(41)
            assert caplog.handler.level == 41

        def test2(caplog):
            assert caplog.handler.level == 0

        def test3(caplog):
            assert caplog.handler.level == 0
            caplog.set_level(43)
            assert caplog.handler.level == 43
    """
    )
    result = pytester.runpytest()
    result.assert_outcomes(passed=3)
Ensure that 'set_level' is undone after the end of the test (handler).

    Issue #7569. Tests the handler level specifically.
    
testing/logging/test_fixture.py