test_distutils changes global logging level for distutils. This affects test_shutil. In Python 2.7: $ ./python -m test.regrtest test_distutils test_shutil [1/2] test_distutils [2/2] test_shutil test test_shutil produced unexpected output: ********************************************************************** zip -q -r archive2.zip dist ********************************************************************** 1 test OK. 1 test failed: test_shutil Python 3 testing is more lenient, but produces unexpected output too. The global logging level is changed in Distribution.parse_command_line() by calling log.set_verbosity(). Proposed patch restores the value of the global logging level in tests that change it.
Instead of a context manager, why not adding a addCleanup() in setUp() method of test cases? You might also add a "resource" test in regrtest, but this one might be overkill, since tests using distutils are known (test_distutils), no? Lib/distutils/tests/support.py: + threshold = log.set_threshold(log.WARN) + log.set_threshold(threshold) + yield threshold I would prefer to have a log.get_threshold() function (or log._get_threshold() if you don't want to modify the public API), or even read log._global_log.threshold. test_shutil.py: - with support.change_cwd(root_dir), captured_stdout(): + with support.change_cwd(root_dir): Why do you remove captured_stdout() here?
test_distutils_restore_log_level_2.patch looks good to me, it's simpler than the first version. I hope that it will fix the sporadic failures, thanks for working on fixing Python 2.7 buildbots!
Thank you Victor for your review. It's my fault, I missed this failure when added test_zipfile_vs_zip in . Perhaps because ran only singular test test_shutil on 2.7, and on 3.x an unexpected output doesn't break tests. In any case it is more right to fix the original cause in test_distutils that just silence an unexpected output.