This is the behavior of the default __import__() function, which doesn't
validate the existence of the fromlist items. Later on, the missing attribute
is detected while processing the import statement.
https://hg.python.org/cpython/file/v2.7.13/Python/import.c#l2575
The comtypes library relies on this (maybe) undocumented behavior, and we
got a bug report to TortoiseHg, sigh.
https://bitbucket.org/tortoisehg/thg/issues/4647/
The test added at 0be19b069edf verifies the behavior of the import statement,
so this patch only adds the test of __import__() function and works around
CPython/PyPy difference.
The stringification of sys.stderr is different in PyPy:
$ pypy -c 'import sys; print sys.stderr'
<open file '<fdopen>', mode 'w' at 0x00a42080>
$ python -c 'import sys; print sys.stderr'
<open file '<stderr>', mode 'w' at 0x10025a270>
The test will now ignore the exact value between the angle brackets.
The Windows-only wrapper around stdout is causing both of these tests to fail.
test-demandimport fails because it tries to print repr(sys.stdout). Use
stderr instead since that is not wrapped.
test-trusted fails because the wrapper doesn't handle softspace and an
unexpected extra space gets printed.