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

Documentation of unittest -p usage wrong on windows. #67001

Closed
rbtcollins opened this issue Nov 7, 2014 · 15 comments
Closed

Documentation of unittest -p usage wrong on windows. #67001

rbtcollins opened this issue Nov 7, 2014 · 15 comments
Labels
docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@rbtcollins
Copy link
Member

BPO 22812
Nosy @rbtcollins, @bitdancer, @zware
Files
  • cpython-22812-discovery-quotes-v1.patch: Version 1 of the patch
  • cpython-22812-discovery-quotes-v2.patch: Version 2 of the patch (doc change only)
  • cpython-22812-discovery-double-quotes-v3.patch: Version 3 - docs with double-quotes
  • 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 2015-08-24.00:17:41.289>
    created_at = <Date 2014-11-07.10:00:09.410>
    labels = ['type-feature', 'docs']
    title = 'Documentation of unittest -p usage wrong on windows.'
    updated_at = <Date 2015-08-24.00:17:41.221>
    user = 'https://github.com/rbtcollins'

    bugs.python.org fields:

    activity = <Date 2015-08-24.00:17:41.221>
    actor = 'rbcollins'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2015-08-24.00:17:41.289>
    closer = 'rbcollins'
    components = ['Documentation']
    creation = <Date 2014-11-07.10:00:09.410>
    creator = 'rbcollins'
    dependencies = []
    files = ['38939', '39025', '39033']
    hgrepos = []
    issue_num = 22812
    keywords = ['patch']
    message_count = 15.0
    messages = ['230777', '230811', '230812', '240682', '240828', '240829', '240892', '241059', '241061', '241064', '241072', '241095', '249035', '249036', '249037']
    nosy_count = 6.0
    nosy_names = ['rbcollins', 'r.david.murray', 'docs@python', 'python-dev', 'zach.ware', 'Pam.McANulty']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22812'
    versions = ['Python 3.5']

    @rbtcollins
    Copy link
    Member Author

    From https://code.google.com/p/unittest-ext/issues/detail?id=13

    The following is incorrect on Windows:

    python -m unittest discover -p '*.py'
    

    It should be without the single quotes around the .py:

    python -m unittest discover -p *.py
    

    This needs to be documented.

    @rbtcollins rbtcollins added the docs Documentation in the Doc dir label Nov 7, 2014
    @bitdancer
    Copy link
    Member

    Why doesn't it work with the quotes? Wouldn't it be better to make it work? Or is it as simple as changing the example to use double quotes?

    @rbtcollins
    Copy link
    Member Author

    I agree. IIRC the windows shell passes the argument as "'*.py'" rather than as "*.py", so when we glob it we get no files, as no python files end with an apostrophe.

    @ezio-melotti ezio-melotti added the type-feature A feature request or enhancement label Mar 2, 2015
    @PamMcANulty
    Copy link
    Mannequin

    PamMcANulty mannequin commented Apr 13, 2015

    Remove quotes from quoted patterns only on windows systems (since if the quotes get parsed into the pattern field on a non-windows system, one should respect the user's command line efforts).

    Test uses unittest.mock.patch to test "windows" path.

    @zware
    Copy link
    Member

    zware commented Apr 14, 2015

    I left a comment on Rietveld. Also, the test doesn't pass on Windows:

    test test_unittest failed -- Traceback (most recent call last):
      File "C:\Data\code\CPython\hg.python.org\devinabox\cpython\lib\unittest\test\t
    est_discovery.py", line 677, in test_command_line_handling_do_discovery_calls_lo
    ader
        self.assertEqual(Loader.args, [('.', "'test*.py'", None)])
    AssertionError: Lists differ: [('.', 'test*.py', None)] != [('.', "'test*.py'",
    None)]

    First differing element 0:
    ('.', 'test*.py', None)
    ('.', "'test*.py'", None)

    • [('.', 'test*.py', None)]
      + [('.', "'test*.py'", None)]
      ? + +

    @zware
    Copy link
    Member

    zware commented Apr 14, 2015

    As an aside: Pam, I got a bounce notice from the email that Rietveld tried to send you. It claims that your email account is disabled, though I suspect that might be it's way of saying it thinks Rietveld is spam (since it tries to send in the reviewer's name).

    @zware
    Copy link
    Member

    zware commented Apr 14, 2015

    Looking deeper at this, I think the best solution is to use '"*.py"' instead of "'*.py'" without changing the code at all. Quoting on the Windows shell is somewhat of a nightmare (see my example on Rietveld), but using double quotes works on both Windows and Linux.

    @PamMcANulty
    Copy link
    Mannequin

    PamMcANulty mannequin commented Apr 14, 2015

    This version of the patch just updates the docs. Since the quotes aren't really necessary for the example to work, the patch removes the single quotes from the example.

    I don't think that the python unittest documentation should explain/document the various command-line quoting rules, so let's not add un-necessary confusion.

    @bitdancer
    Copy link
    Member

    Ah, but the quotes *are* necessary on unix. Without the quotes, the shell will try to fill in the glob, which will either fail with an error that no files match or (worse) succeed and turn the pattern into a list of filenames. Which is why Zach is suggesting using double quotes, which have the (same) documented result on both unix and windows, even though *why* they have the same result is slightly different on the two systems.

    @bitdancer
    Copy link
    Member

    I should clarify that some unix shells will pass the glob through if there are no files that match, while some will generate the 'no matching files' error message. The former is actually worse, since that means that sometimes it works without the quotes, and sometimes it doesn't.

    @PamMcANulty
    Copy link
    Mannequin

    PamMcANulty mannequin commented Apr 15, 2015

    Thanks, Zach for both the comments and the mention of the email bounce. I changed jobs and didn't have this site listed in my "must update email address list" (fixed now)

    Should I re-update the doc patch and put in double quotes?

    @PamMcANulty
    Copy link
    Mannequin

    PamMcANulty mannequin commented Apr 15, 2015

    Here's a version of the docs with double quotes

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 24, 2015

    New changeset 3256764fadae by Robert Collins in branch '2.7':
    Issue bpo-22812: Fix unittest discovery examples.
    https://hg.python.org/cpython/rev/3256764fadae

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 24, 2015

    New changeset e285606efb82 by Robert Collins in branch '3.4':
    Issue bpo-22812: Fix unittest discovery examples.
    https://hg.python.org/cpython/rev/e285606efb82

    New changeset 875a851b9d5a by Robert Collins in branch '3.5':
    Issue bpo-22812: Fix unittest discovery examples.
    https://hg.python.org/cpython/rev/875a851b9d5a

    New changeset d9ec88a1e5d6 by Robert Collins in branch 'default':
    Issue bpo-22812: Fix unittest discovery examples.
    https://hg.python.org/cpython/rev/d9ec88a1e5d6

    @rbtcollins
    Copy link
    Member Author

    Thanks for the patch!

    @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
    docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants