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
test_argparse failure in interactive mode #56115
Comments
(3.1 not checked because it seems not to have test_argparse) C:\Programs\Python32>python -m test -v test_argparse but interactively (command window interpreter or IDLE shell, 3.2 or 2.7)
>>> from test import test_argparse as t; t.test_main() gives two failures related to extra spaces in usage string (I added a couple of newlines for clarity). I have no idea if problem is with argparse, test_argparse, regrtest, unittest, or interactive versus batch mode. ====================================================================== Traceback (most recent call last):
File "C:\Programs\Python32\lib\test\test_argparse.py", line 2217, in test_groups_parents
'''.format(self.main_program)))
File "C:\Programs\Python32\lib\test\test_argparse.py", line 29, in assertEqual
super(TestCase, self).assertEqual(obj1, obj2)
AssertionError:
'usage: [-h] [-w W] [-x X] [-y Y | -z Z]\n\noptional arguments:\n -h, --help s [truncated]... !=
'usage: [-h] [-w W] [-x X] [-y Y | -z Z]\n\noptional arguments:\n -h, --help [truncated]...
- usage: [-h] [-w W] [-x X] [-y Y | -z Z]
+ usage: [-h] [-w W] [-x X] [-y Y | -z Z]
? +
optional arguments:
-h, --help show this help message and exit
-y Y
-z Z
g:
gd
-w W
-x X ====================================================================== Traceback (most recent call last):
File "C:\Programs\Python32\lib\test\test_argparse.py", line 2188, in test_parent_help
'''.format(self.main_program)))
File "C:\Programs\Python32\lib\test\test_argparse.py", line 29, in assertEqual
super(TestCase, self).assertEqual(obj1, obj2)
AssertionError:
'usage: [-h] [-b B] [--d D] [--w W] [-y Y] a z\n\npositional arguments:\n a\n [truncated]... !=
'usage: [-h] [-b B] [--d D] [--w W] [-y Y] a z\n\npositional arguments:\n a\n [truncated]...
- usage: [-h] [-b B] [--d D] [--w W] [-y Y] a z
+ usage: [-h] [-b B] [--d D] [--w W] [-y Y] a z
? +
positional arguments:
a
z
optional arguments:
-h, --help show this help message and exit
-b B
--w W
c:
--d D
x:
-y Y Ran 1536 tests in 29.438s FAILED (failures=2)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
from test import test_argparse as t; t.test_main()
File "C:\Programs\Python32\lib\test\test_argparse.py", line 4423, in test_main
support.run_unittest(__name__)
File "C:\Programs\Python32\lib\test\support.py", line 1145, in run_unittest
_run_suite(suite)
File "C:\Programs\Python32\lib\test\support.py", line 1128, in _run_suite
raise TestFailed(err)
test.support.TestFailed: multiple errors occurred |
If I put the same line I ran interactively in a file and run it from test import test_argparse as t; t.test_main() all tests pass. So it is specifically a problem from the interactive prompt. |
That happens because argparse uses |
Thanks for the diagnosis. I am glad it is something simple. |
I don’t know if we should go out of our way to support running tests in interactive mode. Running them from regrtest is the recommended way. |
Unless Terry wants to contribute a fix I suggest closing this. |
Ahem. Interactive mode is an approved method of running Python code, along with batch mode. The core interpreter and stdlib modules should run correctly in both modes. So the entire test suite should pass in both modes too. If the tests are written correctly, failure would indicate a bug in the tested component. That aside, the doc for test/ does not contain 'recommended' and does not discuss running a single test. What I did is the easiest way on Windows. In this case, following Andreas' remark, the bug is in the test, not the module, in that it miscalculates the expected output in the corner case of a null program name. At lines 2172 and 2205 in the 3.2.0 version of test_argparse.py, changing '''usage: {} ... to prog = self.main_program
...
'''usage: {}{}...
...
'''.format(prog, ' ' if prog else '') fixes the problem. |
|
That is not guaranteed for any particular piece of Python code in the standard library. In particular it is not amenable to test automation, so it is certainly not a requirement that tests pass in this mode. (What is the *use case* for running a command line argument parser in interactive mode?) I'm certainly not opposed to fixing tests so that they do pass when run like this, but I disagree that it is a "bug". |
Unless the doc for a module explicitly diclaims interactive mode (as does multiproccessing), it should run interactively as documented. Batch and interactive are not mutually exclusive; python -i runs a file in batch mode and switches to interactive mode. IDLE *always* runs files this way! Interactive exploration is a recommended way to learn Python. I agree that it would be tedious to explore the usage of argparse, for instance, by typing everything at the interactive prompt. But one could, for instance, write a file that puts fake content into sys.argv, sets up option and arg specs, and parses. After running the file in IDLE (or with python -i), one might interactively modify sys.argv or the specs and reparse to see what changes. In any case, using a module interactively and running its test interactively are different things. If a test cannot run interactively, it should be marked as 'skip if interactive' just as with all the other skip conditions. (Skip if not self.program_name might do it.) But this is all moot for this issue. |
Where is it documented that all tests will run from the IDLE prompt? I have *never* heard this claim before. I have nothing against tests supporting this, but those who want it to happen will have to do the work. |
Terry, I think you can apply the patch you proposed in msg137085 and close this issue. |
I will when I get setup to do that again. |
I discovered that after our discussion in this report and added it to the devguide in c18fd0ee23ed. BTW I agree with Ezio that the fix you proposed should be committed. |
New changeset b950267efd59 by Terry Jan Reedy in branch '3.2': |
New changeset ec32e6ec16fc by Terry Jan Reedy in branch '2.7': |
This was committed on py3k in 4f8c24830a5c. Terry, can the issue be closed? |
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: