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.regrtest does not support multiple -x flags #72595
Comments
Until python3.6.0a04 it was possible to pass multiple times the -x option at regrtest. However since the 3.6.0b1 when trying the same thing I get an error. Test names are random. python3 -m test.regrtest -x test_venv -x test_gdb If however I omit the second -x, the tests run fine and correctly exclude the specific tests. Was the change intentional or a side effect from something else? |
Seems this is related to some changes in argparse. |
That sounds like a regression in argparse that we'd better track down. |
This regression is introduced in 4df2d43e995d. And actually to skip multiple tests, you should use python3 -m test.regrtest -x test_venv test_gdb. Although Charalampos's example could work, it actually treats -x as a test. |
So should we still consider this a regression? Actually -x is used as a hint flag and should not be used as -x arg pair. The right usage could still work now. |
This issue is not specific to -x, but affects all options. Following lines work:
But following lines don't work:
|
These also fail in 3.6.0a4. You can only specify options after args now. test_binop is not valid option. Isn't this the expected behaviour? |
Indeed, previously -x in the middle of test names worked only by accident, because it was interpreted as the name of excluded test. Now it stops positional arguments. Current behavior is explainable, but surprising. This part of argparse is not clear and can cause unexpected effects. I afraid that argparse is incorrectly used in tarfile. |
OK, so this isn't a regression in argparse itself? I thought you meant it was, which is why I set it to release blocker. |
No, this is not a regression in argparse itself, nor in regrtest (as Xiang pointed, original example is incorrect use). But I'm not sure about the support of options after positional arguments. This is dangerous feature. I'm going to investigate this further and find whether all is correct or needed some code or documentation changes. |
Xiang: "This regression is introduced in 4df2d43e995d." Sorry, my commit message is very short. I made this change because I was very annoying of getting "unknown test -m" and "unknown test test_access" when using the -m option to filter tests: ./python -m test test_os -m test_access It's annoying to have to type: ./python -m test -m test_access test_os By the way, it seems weird to have two consecutive -m with two different meanings ;-) I didn't expect any regression, since argparse is smart to parse arguments. If something is wrong, I wouldn't call it a bug in argparse, but a bug in regrtest, how regrtest uses argparse. |
Attached patch should fix the issue. I didn't know that argparse was so strict: "arg1 -v arg2" is not supported by default, see the issue bpo-14191, whereas it works well with optparse. The patch uses parse_known_args() as a workaround, and then manually checks for unknown options. |
New changeset af06d9616c29 by Victor Stinner in branch '3.5': New changeset 26249f82c15d by Victor Stinner in branch '3.6': New changeset 9f03b3dbb929 by Victor Stinner in branch 'default': |
Thanks for the bug report Charalampos! It's now fixed. --
To be clear: the regrtest parser of command line argument was broken since Python 2.7 at least. "./python -m test.regrtest -v test_binop -v test_unaryop" on Python 2.7 tries to run "-v" test... I fixed Python 3.5, 3.6 and 3.7, but not Python 2.7. Python 3 uses argparse, whereas Python 2 uses getopt. I'm not interested to try to fix the Python 2 code using getopt. |
What is the difference between using parse_known_args() and nargs=argparse.REMAINDER? |
Serhiy Storchaka added the comment:
Using REMAINDER, args become ["b", "-c", "d"] for -a b -c d. I would be happy to not use parse_known_args(), but I didn't find how. |
Misc/NEWS
so that it is managed by towncrier #552Note: 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: