Author terry.reedy
Recipients ezio.melotti, michael.foord, pitrou, serhiy.storchaka, terry.reedy
Date 2013-08-11.18:22:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1376245325.09.0.785348034541.issue18702@psf.upfronthosting.co.za>
In-reply-to
Content
The patch applies cleanly on my 3.4 Win 7, fresh debug build. Somewhat fortuitously, as it turns out, I have not downloaded the files needed for ssl support. For each modified file, I ran
python_d -m test -v test_xxx

test test_nntplib crashed -- Traceback (most recent call last):
  File "F:\Python\dev\py34\lib\test\regrtest.py", line 1298, in runtest_inner
    the_module = importlib.import_module(abstest)
  File "F:\Python\dev\py34\lib\importlib\__init__.py", line 93, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1613, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1594, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1561, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 607, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1056, in load_module
  File "<frozen importlib._bootstrap>", line 926, in load_module
  File "<frozen importlib._bootstrap>", line 274, in _call_with_frames_removed
  File "F:\Python\dev\py34\lib\test\test_nntplib.py", line 305, in <module>
    class NetworkedNNTP_SSLTests(NetworkedNNTPTests):
  File "F:\Python\dev\py34\lib\test\test_nntplib.py", line 315, in NetworkedNNTP_SSLTests
    NNTP_CLASS = nntplib.NNTP_SSL
AttributeError: 'module' object has no attribute 'NNTP_SSL'

I do not understand the frozen importlib stuff, but nntplib._have_ssl is False, so the line asking for the non-existent attribute should not be executed.

The problem is that changing a guard from 'if hasattr' to the decorator is a *semantic change* in that it allows execution of the guarded statement. Skips only skip function calling. For a function statement, creating a function object from the compiled code object and binding a name is trivial. Not calling the function is the important part. For a class with code other than function definitions, the difference is crucial, as the above shows.

The general solution is to put class code inside a function so it is only executed later, as part of the test process, rather than during inport.
    @classmethod
    def setUpClass(cls):
        cls.NNTP_CLASS = nntplib.NNTP_SSL

In this case, you could instead guard it with 'if _have_ssl', but since this assignment is the only thing being tested by this test case, it should be inside a method anyway.

I suggest that you review your patch for other changed classes that might have class-level code that could fail with the change to the skip decorator.

Here is similar problem: trying to subclass a class that does not exist.
test test_socketserver crashed
  File "F:\Python\dev\py34\lib\test\test_socketserver.py", line 50, in <module>
    socketserver.UnixStreamServer):
AttributeError: 'module' object has no attribute 'UnixStreamServer'

class ForkingUnixStreamServer(socketserver.ForkingMixIn,
                              socketserver.UnixStreamServer): pass

I think you have to go back to 'if HAVE_UNIX_SOCKETS:' for this. Or re-factor somehow.

---
I cannot help wondering whether test_math.xxx.test_exceptions should still be (normally) disabled. I sent Mark Dickinson a separate note.
History
Date User Action Args
2013-08-11 18:22:05terry.reedysetrecipients: + terry.reedy, pitrou, ezio.melotti, michael.foord, serhiy.storchaka
2013-08-11 18:22:05terry.reedysetmessageid: <1376245325.09.0.785348034541.issue18702@psf.upfronthosting.co.za>
2013-08-11 18:22:05terry.reedylinkissue18702 messages
2013-08-11 18:22:04terry.reedycreate