Skip to content
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

Closed
stratakis mannequin opened this issue Oct 10, 2016 · 16 comments
Closed

test.regrtest does not support multiple -x flags #72595

stratakis mannequin opened this issue Oct 10, 2016 · 16 comments
Labels
3.7 (EOL) end of life tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@stratakis
Copy link
Mannequin

stratakis mannequin commented Oct 10, 2016

BPO 28409
Nosy @vstinner, @larryhastings, @ned-deily, @bitdancer, @serhiy-storchaka, @zhangyangyu, @stratakis
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • regrtest_cli.patch
  • 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:

    assignee = None
    closed_at = <Date 2016-10-17.16:19:22.967>
    created_at = <Date 2016-10-10.17:37:52.698>
    labels = ['3.7', 'type-bug', 'tests']
    title = 'test.regrtest does not support multiple -x flags'
    updated_at = <Date 2017-03-31.16:36:17.086>
    user = 'https://github.com/stratakis'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:17.086>
    actor = 'dstufft'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-10-17.16:19:22.967>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2016-10-10.17:37:52.698>
    creator = 'cstratak'
    dependencies = []
    files = ['45056']
    hgrepos = []
    issue_num = 28409
    keywords = ['patch']
    message_count = 16.0
    messages = ['278435', '278439', '278440', '278458', '278459', '278460', '278461', '278464', '278480', '278482', '278487', '278490', '278813', '278814', '278825', '278826']
    nosy_count = 9.0
    nosy_names = ['bethard', 'vstinner', 'larry', 'ned.deily', 'r.david.murray', 'python-dev', 'serhiy.storchaka', 'xiang.zhang', 'cstratak']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28409'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @stratakis
    Copy link
    Mannequin Author

    stratakis mannequin commented Oct 10, 2016

    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
    usage: python -m test [options] [test_name1 [test_name2 ...]]
    python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]]
    regrtest.py: error: unrecognized arguments: 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?

    @stratakis stratakis mannequin added the tests Tests in the Lib/test dir label Oct 10, 2016
    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Oct 10, 2016
    @serhiy-storchaka
    Copy link
    Member

    Seems this is related to some changes in argparse.

    @bitdancer
    Copy link
    Member

    That sounds like a regression in argparse that we'd better track down.

    @zhangyangyu
    Copy link
    Member

    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.

    @zhangyangyu
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member

    This issue is not specific to -x, but affects all options. Following lines work:

    ./python -m test.regrtest -v test_unary test_binop
    ./python -m test.regrtest -u all test_unary test_binop
    ./python -m test.regrtest test_unary test_binop -v
    ./python -m test.regrtest test_unary test_binop -u all
    

    But following lines don't work:

    ./python -m test.regrtest test_unary -v test_binop
    ./python -m test.regrtest test_unary -u all test_binop
    

    @zhangyangyu
    Copy link
    Member

    ./python -m test.regrtest test_unary -v test_binop
    ./python -m test.regrtest test_unary -u all test_binop

    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?

    @serhiy-storchaka
    Copy link
    Member

    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.

    @bitdancer
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member

    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.

    @vstinner
    Copy link
    Member

    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.

    @vstinner
    Copy link
    Member

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 17, 2016

    New changeset af06d9616c29 by Victor Stinner in branch '3.5':
    Issue bpo-28409: regrtest: fix the parser of command line arguments.
    https://hg.python.org/cpython/rev/af06d9616c29

    New changeset 26249f82c15d by Victor Stinner in branch '3.6':
    Merge 3.6: Issue bpo-28409: regrtest: fix the parser of command line arguments.
    https://hg.python.org/cpython/rev/26249f82c15d

    New changeset 9f03b3dbb929 by Victor Stinner in branch 'default':
    Merge 3.7: Issue bpo-28409: regrtest: fix the parser of command line arguments.
    https://hg.python.org/cpython/rev/9f03b3dbb929

    @vstinner
    Copy link
    Member

    Thanks for the bug report Charalampos! It's now fixed.

    --

    Until python3.6.0a04 it was possible to pass multiple times the -x option at regrtest.

    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.

    @serhiy-storchaka
    Copy link
    Member

    What is the difference between using parse_known_args() and nargs=argparse.REMAINDER?

    @vstinner
    Copy link
    Member

    Serhiy Storchaka added the comment:

    What is the difference between using parse_known_args() and
    nargs=argparse.REMAINDER?

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants