summaryrefslogtreecommitdiffstats
path: root/Lib/test/test___all__.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-02-12 03:27:31 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-02-12 03:27:31 (GMT)
commit76c066b103c23702d328aa9056c65d02abb8a3ac (patch)
tree5f6fb7a7cf233e158ba457c8ddb5176b3fa414b1 /Lib/test/test___all__.py
parentc62c81e013fbc9a726493870c3624b60ae63a757 (diff)
downloadcpython-76c066b103c23702d328aa9056c65d02abb8a3ac.zip
cpython-76c066b103c23702d328aa9056c65d02abb8a3ac.tar.gz
cpython-76c066b103c23702d328aa9056c65d02abb8a3ac.tar.bz2
test_pty started failing on Windows, but if and only if test___all__ was
run first. Indirectly due to Skip adding check_all("pty") to test___all__: that caused the expected ImportError due to pty.py trying to import the non-existent FCNTL to get handled by test___all__, leaving a partial module object for pty in sys.modules, which caused the later import of pty via test_pty to succeed. Then test_tpy died with an AttributeError, due to trying to access attributes of pty that didn't exist. regrtest viewed that as a failure rather than the appropriate "test skipped". Fixed by deleting partial module objects in test___all__ when test___all__ handles an ImportError.
Diffstat (limited to 'Lib/test/test___all__.py')
-rw-r--r--Lib/test/test___all__.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index cced859..875d99d 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -6,8 +6,22 @@ def check_all(modname):
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
+ # 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
+ # AtttributeError 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
verify(hasattr(sys.modules[modname], "__all__"),
"%s has no __all__ attribute" % modname)