New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doctest module does not work with zipped packages #48447
Comments
With attached teestmodule.zip and svn revision 67006, $ ./python.exe testmodule.zip
Traceback (most recent call last):
File "/Users/sasha/Work/python-svn/trunk/Lib/runpy.py", line 121, in
_run_module_as_main
"__main__", fname, loader, pkg_name)
File "/Users/sasha/Work/python-svn/trunk/Lib/runpy.py", line 34, in
_run_code
exec code in run_globals
File "testmodule.zip/__main__.py", line 7, in <module>
File "/Users/sasha/Work/python-svn/trunk/Lib/doctest.py", line 1817,
in testmod
for test in finder.find(m, name, globs=globs,
extraglobs=extraglobs):
File "/Users/sasha/Work/python-svn/trunk/Lib/doctest.py", line 842, in
find
self._find(tests, obj, name, module, source_lines, globs, {})
File "/Users/sasha/Work/python-svn/trunk/Lib/doctest.py", line 884, in
_find
test = self._get_test(obj, name, module, globs, source_lines)
File "/Users/sasha/Work/python-svn/trunk/Lib/doctest.py", line 965, in
_get_test
if filename[-4:] in (".pyc", ".pyo"):
TypeError: 'NoneType' object is unsubscriptable |
Attached patch addresses the crash, but two issues remain: $ ./python.exe testmodule.zip
**********************************************************************
File "__main__", line ?, in __main__.c
Failed example:
'line 2'
Expected nothing
Got:
'line 2'
**********************************************************************
1 items had failures:
1 of 1 in __main__.c
***Test Failed*** 1 failures. The line number for the failed example cannot be found and file name is |
The next patch, doctest-1.patch addresses the line number issue, but the $ ./python.exe testmodule.zip
**********************************************************************
File "__main__", line 2, in __main__.c
Failed example:
'line 2'
Expected nothing
Got:
'line 2'
**********************************************************************
1 items had failures:
1 of 1 in __main__.c
***Test Failed*** 1 failures. |
I don't think there is an easy way to fix source file name reporting Setting __file__ to (in the test case) testmodule.zip/main.py will |
runpy needs a non-standard PEP-302 extension to set __file__ correctly |
I created bpo-4512 to implement get_filename extension in zipimport. |
While the patch at bpo-4512 fixes the crash, it does not fix the line |
The precise solution still seems to be debated, so this is out of scope |
Fixed for 2.7 in r67750. Will be ported to 2.6, 3.0 and 3.1. |
Final revisions for fix: |
Nick, Your commit does not fix the line number reporting from doctest failures: $ ./python.exe testmodule.zip
**********************************************************************
File "testmodule.zip/__main__.py", line ?, in __main__.c
... Note the '?' in the output. Did you miss the doctest.py changes in There is also a problem of __main__.c which my patch does not address, On Sun, Dec 14, 2008 at 7:11 AM, Nick Coghlan <report@bugs.python.org> wrote:
|
Re-opening, pending development of a fully passing test specifically for |
I have a test case locally that demonstrates both the missing line It still seems to me that there is something going wrong at a deeper |
It turns out you were pretty close to pinpointing the problem in The __main__.c thing turned out just to be a red herring caused by the Checkin versions: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: