-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: add cmdline parameters #55599
Comments
doctest module need to parse -h/--help parameters, and accept flags like ELLIPSIS from command line. Otherwise it very hard to debug tests like contained in the attached README. It is also worth to make it parameter compatible with unittest.main() Usage: tests.py [options] [test] [...] Options: |
Here is a patch that implements the ones I'm interested in (-o for any option, and -f as a shortcut for -o FAIL_FAST). It's a good question whether doctest should support other unittest options, but doing so is more complicated than supporting -o and -f. Adding a couple people to nosy who have an interest in testing and doctest, hoping for a patch review :) |
Oh, a documentation update is still needed here, so I guess I'm not really ready for review yet :( |
Patch updated with documentation. |
I will probably commit this tomorrow if there are no objections. |
Patch updated per Barry's review comments. |
New changeset ae802dc4dcd4 by R David Murray in branch 'default': |
Committed. Thanks for the review, Barry. |
The new tests added in changeset ae802dc4dcd4 are failing on some buildbots. I can reproduce the issue on my Linux box (Fedora 18). First failure of "./python -m test test_doctest": [1/1] test_doctest File "/home/haypo/prog/python/default/Lib/test/test_doctest.py", line 2627, in test.test_doctest.test_CLI The b'\x1b[?1034h' sequence it written by the readline module when it is imported. The readline module is imported by pdb, which is used by doctest. The following article proposes set to TERM environment variable to "linux" to workaround the issue: It works: $ echo $TERM # yeah, Fedora supports 256 colors!
xterm-256color
$ ./python -c 'import readline'|hexdump -C
00000000 1b 5b 3f 31 30 33 34 68 |.[?1034h|
00000008
$ TERM=linux ./python -c 'import readline'|hexdump -C This issue was reported to OpenSuse in 2009: The issue is not specific to Python. Just one another example with Octave (issue closed as "not a bug"): The issue was also reported upstream (bug-readline mailing list) a few days ago: |
Attached doctest_term_dummy.patch: workaround the issue by setting TERM env var to "dummy". Why is test_CLI() implemented using a doctest? Why not reusing the unittest module to benefit from test.support and test.regrtest? (Hint: I don't like doctests :-)) |
test_doctest.test_CLI() is also failing on Windows: It looks like an issue with Windows newline (\r\n) versus UNIX newline (\n). test_CLI() decodes the bytes output from UTF-8, but do not normalize newlines. The universal_newlines=True option can be passed to subprocess, which is not possible currently using script_helper. Is there function somewhere else to normalize newlines? |
It is implemented as a doctest because everything else in that test module is implemented as a doctest. And clearly this reveals a bug of some sort. Perhaps the dummy trick needs to be done by doctest itself? (I will need to read your post over more carefully and understand the issue better.) As for the windows failures, my apologies. I knew I would need to check windows after the commit when I wrote the code, but I forgot to actually do it. |
No problem, it's so easy to forget Windows :-) And we have buildbots 2013/6/25 R. David Murray <report@bugs.python.org>:
|
The issue really comes from the readline module. The workaround is to set an environment variable, which affects the whole process (all threads). Only setting TERM for test_CLI() is fine, because it's the only test running doctest in a subprocess. Hum, we may set TERM=dummy in script_helper directly, because this module tries to run Python in a fresh environment. It uses "python -E" for example. |
New changeset 8f22e03f5f07 by R David Murray in branch 'default': |
Fixed for this test. It would probably be worthwhile to improve script_helpers, I'll open a new issue for that. |
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: