[1.5.x] Correctly restore warning capture after logging tests.

This is a fix to the wrong behavior that 15c3906eeb introduced.

Backport of 4befef9 from trunk.