This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_distutils provokes unexpected output in test_shutil
Type: behavior Stage: resolved
Components: Distutils, Tests Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: dstufft, eric.araujo, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2015-11-12 12:34 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_distutils_restore_log_level.patch serhiy.storchaka, 2015-11-12 12:34 review
test_distutils_restore_log_level_2.patch serhiy.storchaka, 2015-11-12 15:25 review
Messages (6)
msg254529 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-12 12:34
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.
msg254530 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-12 13:07
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?
msg254533 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-12 15:25
Here is a patch that just uses addCleanup() as Victor suggested.

> Why do you remove captured_stdout() here?

It is no longer needed.
msg254534 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-12 15:26
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!
msg254539 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-12 17:48
New changeset 4461613ffe78 by Serhiy Storchaka in branch '3.4':
Issue #25607: Restore old distutils logging threshold after running tests that
https://hg.python.org/cpython/rev/4461613ffe78

New changeset d7741afd8347 by Serhiy Storchaka in branch '2.7':
Issue #25607: Restore old distutils logging threshold after running tests that
https://hg.python.org/cpython/rev/d7741afd8347

New changeset 7411830c7b24 by Serhiy Storchaka in branch '3.5':
Issue #25607: Restore old distutils logging threshold after running tests that
https://hg.python.org/cpython/rev/7411830c7b24

New changeset 9f6e43a6b3e0 by Serhiy Storchaka in branch 'default':
Issue #25607: Restore old distutils logging threshold after running tests that
https://hg.python.org/cpython/rev/9f6e43a6b3e0
msg254540 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-12 17:57
Thank you Victor for your review.

It's my fault, I missed this failure when added test_zipfile_vs_zip in issue24982. 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.
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69793
2015-11-12 17:57:19serhiy.storchakasetstatus: open -> closed
messages: + msg254540

assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2015-11-12 17:48:31python-devsetnosy: + python-dev
messages: + msg254539
2015-11-12 15:26:48vstinnersetmessages: + msg254534
2015-11-12 15:25:18serhiy.storchakasetfiles: + test_distutils_restore_log_level_2.patch

messages: + msg254533
2015-11-12 13:07:02vstinnersetnosy: + vstinner
messages: + msg254530
2015-11-12 12:34:44serhiy.storchakacreate