R. David Murray added the comment: This is not a bug, it is a feature. python -m doctest can be used to run tests from files that are *not* python files.
I wouldn't call tracebacks with name errors as a silent failure :) As you say, there is no easy way to use doctest to run doctests in a script file that is not a .py file, since it can't be imported, so I'm not sure there is anything that can be done here. Even trying to guess that it is a python file and issuing an error message or even a warning is problematic from a backward compatibility standpoint, since there may be people with files that look like python files that are *meant* to be run as doctests. I'm guessing script-with-testable-docstrings isn't *common*, though I can easily imagine myself writing one (using subprocess to re-exec the script). What I actually did, though, was have a command line switch that runs the doctests by calling testmod from within the script, which is how doctest is designed to work. So, we can see what other people think about the idea of looking for a shebang line and issuing an error message. Or maybe a warning...or an error plus a command line switch to force it to process the script anyway? ---------- nosy: +r.david.murray title: python -m doctest file_with_no_py_extension # silently fails -> python -m doctest script_file_with_no_py_extension produces confusing NameErrors versions: +Python 3.6 -Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27447> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com