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_py3kwarn fails on Windows
Type: behavior Stage: resolved
Components: Tests, Windows Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, giampaolo.rodola, ncoghlan, python-dev, serhiy.storchaka, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords: patch

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

Files
File name Uploaded Description Edit
test_py3kwarn-2.patch vstinner, 2015-09-03 07:38 review
unicodedata.patch vstinner, 2015-09-03 07:43 review
Messages (9)
msg235228 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-02 07:21
http://buildbot.python.org/all/builders/x86%20XP-4%202.7/builds/3092/steps/test/logs/stdio

======================================================================
FAIL: test_optional_module_removals (test.test_py3kwarn.TestStdlibRemovals)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\cygwin\home\db3l\buildarea\2.7.bolen-windows\build\lib\test\test_py3kwarn.py", line 395, in test_optional_module_removals
    self.check_removal(module_name, optional=True)
  File "D:\cygwin\home\db3l\buildarea\2.7.bolen-windows\build\lib\test\test_py3kwarn.py", line 379, in check_removal
    .format(module_name))
AssertionError: DeprecationWarning not raised for imageop

----------------------------------------------------------------------
msg235275 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-02-02 17:24
Looks like a test ordering issue. When test_imageop runs before test_py3kwarn, the warning has presumably already been shown once and so isn't triggered when the test is looking for it (compare build 3092 linked above with 3093, which passed).

I haven't looked any further into this, but I don't see how it's Windows specific. Adding the test coverage folks, since nobody seems to obviously own test_py3kwarn.
msg235279 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-02 18:23
I can't reproduce the failure on Linux.
msg249608 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2015-09-03 06:25
Could this have anything to do with the fact that imageop is a 'built-in' (as opposed to 'extension') module on Windows?  Either way, I'm about ready to just skip testing the warning for that module on Windows.
msg249613 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-03 07:37
> I can't reproduce the failure on Linux.

Do you have a 64-bit system? imageop is only built on 32-bit systems...

> Looks like a test ordering issue. When test_imageop runs before test_py3kwarn, the warning has presumably already been shown once and so isn't triggered when the test is looking for it (compare build 3092 linked above with 3093, which passed).

Yes, I already investigated this issue and I found the same root cause. 

A Python module implemented in C like imageop cannot be reloaded twice. In fact, it can never be unloaded. Since the warning is emited when the module is loaded, the warning will only be emited once.

The issue is not specific to imageop: test_optional_module_removals() must fail on any module implemented in C if the module was already loaded before the test is executed.

> Either way, I'm about ready to just skip testing the warning for that module on Windows.

The correct fix is to skip the test if the module was already loaded and if the module is implemented in C.

Attached patch implements this fix. I don't know how to test if a module is implemented in C or not. I chose to check if its filename ends with ".py" (or .pyc or .pyo).
msg249614 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-03 07:43
To easily test my patch, you can inject a Python 3 DeprecationWarning in the unicodedata module using attached unicodedata.patch, and then modify Lib/test/test_py3kwarn.py to add "unicodedata" to the "optional_modules" list.

I tested my patch on Linux (Fedora 22, 64-bit system).
msg249616 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-03 08:18
The approach LGTM. I left comments on Rietveld.
msg249620 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-03 08:49
New changeset d739bc20d7b2 by Victor Stinner in branch '2.7':
Issue #23375: Fix test_py3kwarn for modules implemented in C
https://hg.python.org/cpython/rev/d739bc20d7b2
msg249621 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-03 08:49
> The approach LGTM. I left comments on Rietveld.

Thanks for the review. I replaced warnings.warn() with a simple print().

This issue should now be fixed.
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67564
2015-09-03 13:56:44berker.peksagsetstage: patch review -> resolved
2015-09-03 08:50:00vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg249621
2015-09-03 08:49:23python-devsetnosy: + python-dev
messages: + msg249620
2015-09-03 08:18:28serhiy.storchakasetmessages: + msg249616
stage: patch review
2015-09-03 07:43:17vstinnersetfiles: + unicodedata.patch

messages: + msg249614
2015-09-03 07:38:39vstinnersetfiles: + test_py3kwarn-2.patch
2015-09-03 07:38:33vstinnersetfiles: - test_py3kwarn.patch
2015-09-03 07:37:44vstinnersetfiles: + test_py3kwarn.patch

nosy: + vstinner
messages: + msg249613

keywords: + patch
2015-09-03 06:25:42zach.waresetmessages: + msg249608
2015-02-02 18:23:20serhiy.storchakasetmessages: + msg235279
2015-02-02 17:24:20steve.dowersetnosy: + ncoghlan, giampaolo.rodola, christian.heimes
messages: + msg235275
components: + Tests
2015-02-02 07:21:29serhiy.storchakacreate