regression tests with regrtest.py -r

On a lark, I decided to try running the regression tests with -r, which tells regrtest.py to run the tests in random order. With this, I get the following warnings from test_long.py: ../Lib/test/test_long.py:266: OverflowWarning: integer addition special = [0, 1, 2, 3, sys.maxint-1, sys.maxint, sys.maxint+1] ../Lib/test/test_long.py:287: OverflowWarning: integer addition got = x + y ../Lib/test/test_long.py:291: OverflowWarning: integer subtraction got = x - y ../Lib/test/test_long.py:295: OverflowWarning: integer multiplication got = x * y ../Lib/test/test_long.py:313: OverflowWarning: integer exponentiation got = x ** y ../Lib/test/test_long.py:320: OverflowWarning: integer exponentiation got = pow(x, y, z) ../Lib/test/test_long.py:377: OverflowWarning: integer exponentiation value = 10 ** exp This was with the CVS trunk, which is still virtually identical to the 2.2c1 release. I won't have time to look at them this weekend, but this should be fixed. It may be possible there are other order-dependent behaviors, so it would be really good if people who have time can run the tests with -r on whatever platforms are available and report any other anomolies. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> PythonLabs at Zope Corporation

On a lark, I decided to try running the regression tests with -r,
Good idea!
I've found the cause: test_scope.py contains a call to warnings.resetwarnings(), which removes *all* warning filters, not just those made by the calling module. Because of the way OverflowWarning is suppressed, this removes the "preset" filter that suppresses OverflowWarning. Since an API redesign before the 2.2 release is out of the question, I'm fixing this by removing the resetwarnings() call from test_scope.py and making the filterwarnings() call there a little more specific. --Guido van Rossum (home page: http://www.python.org/~guido/)

[Fred L. Drake, Jr.]
... It may be possible there are other order-dependent behaviors,
There are, but ...
By far the most frequent cause of errors when using -r is bogus module objects left behind in sys.modules on non-Unix platforms that can't import some Unix-specific things. A later attempt to import the same module again doesn't fail, but since the module object is incomplete it fails for some other reason when a test attempts to use the module. I spent countless hours worming around this in the past, but lost heart for it; on my Win9X box, the failing test has usually scrolled off the (50-line) DOS box before regrtest completes, and so also the history of the test ordering that caused it. Heh -- -r failed in test___all__ while I was typing this, but I've no idea why. I'll pursue it until I get sick to death of it <wink>.

Here's one cause of current -r failures on Windows: C:\Code\python\PCbuild>python ../lib/test/regrtest.py \ test_pty test___all__ test_pty test test_pty skipped -- No module named termios test___all__ test test___all__ failed -- pty has no __all__ attribute 1 test failed: test___all__ 1 test skipped: test_pty Those skips are all expected on win32. It's "the usual": importing pty fails on Windows, but test_pty then leaves behind a bogus pty module object in sys.modules, which fools test___all__. Note that pty.py already has this atrocity from a previous round of -r wrestling: """ # Absurd: import termios and then delete it. This is to force an attempt # to import pty to raise an ImportError on platforms that lack termios. # Without this explicit import of termios here, some other module may # import tty first, which in turn imports termios and dies with an # ImportError then. But since tty *does* exist across platforms, that # leaves a damaged module object for tty in sys.modules, and the import # of tty here then appears to work despite that the tty imported is junk. import termios del termios import tty """ test___all__ also tries to compensate for pty (among others) insanity: """ def check_all(modname): names = {} try: exec "import %s" % modname in names except ImportError: # Silent fail here seems the best route since some modules # may not be available in all environments. # Since an ImportError may leave a partial module object in # sys.modules, get rid of that first. Here's what happens if # you don't: importing pty fails on Windows because pty tries to # import FCNTL, which doesn't exist. That raises an ImportError, # caught here. It also leaves a partial pty module in sys.modules. # So when test_pty is called later, the import of pty succeeds, # but shouldn't. As a result, test_pty crashes with an # AttributeError instead of an ImportError, and regrtest interprets # the latter as a test failure (ImportError is treated as "test # skipped" -- which is what test_pty should say on Windows). try: del sys.modules[modname] except KeyError: pass return """ I've added another hack to regrtest.py to worm around the test_pty followed by test___all__ case (more generally, any test_xxx followed by test___all__ case, when test_xxx fails due to leaving behind a damaged module object for xxx). However, that still doesn't fix test_rlcompleter followed by test___all__ on Windows. In that case, test_rlcompleter leaves behind a damaged rlcompleter module, because rlcompleter.py does exist on Windows (it fails due to the lack of the readline module). leaving-behind-incomplete-module-objects-still-seems-like-a-bad-idea- to-me-ly y'rs - tim

Tim> In case anyone's waiting, stop -- I got sick to death of it, and Tim> won't be checking in anything related. (BTW, there is no Tim> test_rlcompleter, of course; it's the combo of test_sundry and Tim> test___all__ that screws up (both of those import rlcompleter)) A couple wild-ass-guess ideas: * Perhaps more test___all__ smarts are needed? You added a "known skips" list to regrtest.py. test___all__ could perhaps avoid importing any module that's not supposed to work on the current platform. * How about comparing sys.modules.keys() before and after a test and then remove any that were added that are Python modules? (It's not safe to remove extension modules, right?) calling-it-intractable-means-someone-will-solve-it-ly, y'rs, Skip

On a lark, I decided to try running the regression tests with -r,
Good idea!
I've found the cause: test_scope.py contains a call to warnings.resetwarnings(), which removes *all* warning filters, not just those made by the calling module. Because of the way OverflowWarning is suppressed, this removes the "preset" filter that suppresses OverflowWarning. Since an API redesign before the 2.2 release is out of the question, I'm fixing this by removing the resetwarnings() call from test_scope.py and making the filterwarnings() call there a little more specific. --Guido van Rossum (home page: http://www.python.org/~guido/)

[Fred L. Drake, Jr.]
... It may be possible there are other order-dependent behaviors,
There are, but ...
By far the most frequent cause of errors when using -r is bogus module objects left behind in sys.modules on non-Unix platforms that can't import some Unix-specific things. A later attempt to import the same module again doesn't fail, but since the module object is incomplete it fails for some other reason when a test attempts to use the module. I spent countless hours worming around this in the past, but lost heart for it; on my Win9X box, the failing test has usually scrolled off the (50-line) DOS box before regrtest completes, and so also the history of the test ordering that caused it. Heh -- -r failed in test___all__ while I was typing this, but I've no idea why. I'll pursue it until I get sick to death of it <wink>.

Here's one cause of current -r failures on Windows: C:\Code\python\PCbuild>python ../lib/test/regrtest.py \ test_pty test___all__ test_pty test test_pty skipped -- No module named termios test___all__ test test___all__ failed -- pty has no __all__ attribute 1 test failed: test___all__ 1 test skipped: test_pty Those skips are all expected on win32. It's "the usual": importing pty fails on Windows, but test_pty then leaves behind a bogus pty module object in sys.modules, which fools test___all__. Note that pty.py already has this atrocity from a previous round of -r wrestling: """ # Absurd: import termios and then delete it. This is to force an attempt # to import pty to raise an ImportError on platforms that lack termios. # Without this explicit import of termios here, some other module may # import tty first, which in turn imports termios and dies with an # ImportError then. But since tty *does* exist across platforms, that # leaves a damaged module object for tty in sys.modules, and the import # of tty here then appears to work despite that the tty imported is junk. import termios del termios import tty """ test___all__ also tries to compensate for pty (among others) insanity: """ def check_all(modname): names = {} try: exec "import %s" % modname in names except ImportError: # Silent fail here seems the best route since some modules # may not be available in all environments. # Since an ImportError may leave a partial module object in # sys.modules, get rid of that first. Here's what happens if # you don't: importing pty fails on Windows because pty tries to # import FCNTL, which doesn't exist. That raises an ImportError, # caught here. It also leaves a partial pty module in sys.modules. # So when test_pty is called later, the import of pty succeeds, # but shouldn't. As a result, test_pty crashes with an # AttributeError instead of an ImportError, and regrtest interprets # the latter as a test failure (ImportError is treated as "test # skipped" -- which is what test_pty should say on Windows). try: del sys.modules[modname] except KeyError: pass return """ I've added another hack to regrtest.py to worm around the test_pty followed by test___all__ case (more generally, any test_xxx followed by test___all__ case, when test_xxx fails due to leaving behind a damaged module object for xxx). However, that still doesn't fix test_rlcompleter followed by test___all__ on Windows. In that case, test_rlcompleter leaves behind a damaged rlcompleter module, because rlcompleter.py does exist on Windows (it fails due to the lack of the readline module). leaving-behind-incomplete-module-objects-still-seems-like-a-bad-idea- to-me-ly y'rs - tim

Tim> In case anyone's waiting, stop -- I got sick to death of it, and Tim> won't be checking in anything related. (BTW, there is no Tim> test_rlcompleter, of course; it's the combo of test_sundry and Tim> test___all__ that screws up (both of those import rlcompleter)) A couple wild-ass-guess ideas: * Perhaps more test___all__ smarts are needed? You added a "known skips" list to regrtest.py. test___all__ could perhaps avoid importing any module that's not supposed to work on the current platform. * How about comparing sys.modules.keys() before and after a test and then remove any that were added that are Python modules? (It's not safe to remove extension modules, right?) calling-it-intractable-means-someone-will-solve-it-ly, y'rs, Skip
participants (4)
-
Fred L. Drake, Jr.
-
Guido van Rossum
-
Skip Montanaro
-
Tim Peters