Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76c066b

Browse files
committed
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.
1 parent c62c81e commit 76c066b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Lib/test/test___all__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@ def check_all(modname):
66
try:
77
exec "import %s" % modname in names
88
except ImportError:
9-
# silent fail here seems the best route since some modules
10-
# may not be available in all environments
9+
# Silent fail here seems the best route since some modules
10+
# may not be available in all environments.
11+
# Since an ImportError may leave a partial module object in
12+
# sys.modules, get rid of that first. Here's what happens if
13+
# you don't: importing pty fails on Windows because pty tries to
14+
# import FCNTL, which doesn't exist. That raises an ImportError,
15+
# caught here. It also leaves a partial pty module in sys.modules.
16+
# So when test_pty is called later, the import of pty succeeds,
17+
# but shouldn't. As a result, test_pty crashes with an
18+
# AtttributeError instead of an ImportError, and regrtest interprets
19+
# the latter as a test failure (ImportError is treated as "test
20+
# skipped" -- which is what test_pty should say on Windows).
21+
try:
22+
del sys.modules[modname]
23+
except KeyError:
24+
pass
1125
return
1226
verify(hasattr(sys.modules[modname], "__all__"),
1327
"%s has no __all__ attribute" % modname)

0 commit comments

Comments
 (0)