[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

Issue 22812: Documentation of unittest -p usage wrong on windows.

The Wayback Machine - https://web.archive.org/web/20210415120409/https://bugs.python.org/issue22812

Issue22812

classification
Title: Documentation of unittest -p usage wrong on windows.
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Pam.McANulty, docs@python, python-dev, r.david.murray, rbcollins, zach.ware
Priority: normal Keywords: patch

Created on 2014-11-07 10:00 by rbcollins, last changed 2015-08-24 00:17 by rbcollins. This issue is now closed.

Files
File name Uploaded Description Edit
cpython-22812-discovery-quotes-v1.patch Pam.McANulty, 2015-04-13 17:51 Version 1 of the patch review
cpython-22812-discovery-quotes-v2.patch Pam.McANulty, 2015-04-14 23:51 Version 2 of the patch (doc change only) review
cpython-22812-discovery-double-quotes-v3.patch Pam.McANulty, 2015-04-15 12:05 Version 3 - docs with double-quotes review
Messages (15)
msg230777 - (view) Author: Robert Collins (rbcollins) * Date: 2014-11-07 10:00
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.
msg230811 - (view) Author: R. David Murray (r.david.murray) * Date: 2014-11-07 15:16
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?
msg230812 - (view) Author: Robert Collins (rbcollins) * Date: 2014-11-07 15:22
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.
msg240682 - (view) Author: Pam McA'Nulty (Pam.McANulty) * Date: 2015-04-13 17:51
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.
msg240828 - (view) Author: Zachary Ware (zach.ware) * Date: 2015-04-14 01:55
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)]
?        +          +
msg240829 - (view) Author: Zachary Ware (zach.ware) * Date: 2015-04-14 01:59
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).
msg240892 - (view) Author: Zachary Ware (zach.ware) * Date: 2015-04-14 14:22
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.
msg241059 - (view) Author: Pam McA'Nulty (Pam.McANulty) * Date: 2015-04-14 23:51
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.
msg241061 - (view) Author: R. David Murray (r.david.murray) * Date: 2015-04-15 00:06
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.
msg241064 - (view) Author: R. David Murray (r.david.murray) * Date: 2015-04-15 00:43
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.
msg241072 - (view) Author: Pam McA'Nulty (Pam.McANulty) * Date: 2015-04-15 02:15
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?
msg241095 - (view) Author: Pam McA'Nulty (Pam.McANulty) * Date: 2015-04-15 12:05
Here's a version of the docs with double quotes
msg249035 - (view) Author: Roundup Robot (python-dev) Date: 2015-08-24 00:11
New changeset 3256764fadae by Robert Collins in branch '2.7':
Issue #22812: Fix unittest discovery examples.
https://hg.python.org/cpython/rev/3256764fadae
msg249036 - (view) Author: Roundup Robot (python-dev) Date: 2015-08-24 00:16
New changeset e285606efb82 by Robert Collins in branch '3.4':
Issue #22812: Fix unittest discovery examples.
https://hg.python.org/cpython/rev/e285606efb82

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

New changeset d9ec88a1e5d6 by Robert Collins in branch 'default':
Issue #22812: Fix unittest discovery examples.
https://hg.python.org/cpython/rev/d9ec88a1e5d6
msg249037 - (view) Author: Robert Collins (rbcollins) * Date: 2015-08-24 00:17
Thanks for the patch!
History
Date User Action Args
2015-08-24 00:17:41rbcollinssetstatus: open -> closed
resolution: fixed
messages: + msg249037

stage: needs patch -> resolved

2015-08-24 00:16:28python-devsetmessages: + msg249036
2015-08-24 00:11:04python-devsetnosy: + python-dev
messages: + msg249035
2015-04-15 12:05:17Pam.McANultysetfiles: + cpython-22812-discovery-double-quotes-v3.patch

messages: + msg241095

2015-04-15 02:15:27Pam.McANultysetmessages: + msg241072
2015-04-15 00:43:29r.david.murraysetmessages: + msg241064
2015-04-15 00:06:42r.david.murraysetmessages: + msg241061
2015-04-14 23:51:03Pam.McANultysetfiles: + cpython-22812-discovery-quotes-v2.patch

messages: + msg241059

2015-04-14 14:22:41zach.waresetmessages: + msg240892
2015-04-14 01:59:25zach.waresetmessages: + msg240829
2015-04-14 01:55:25zach.waresetnosy: + zach.ware
messages: + msg240828
2015-04-13 17:51:21Pam.McANultysetfiles: + cpython-22812-discovery-quotes-v1.patch

nosy: + Pam.McANulty
messages: + msg240682

keywords: + patch

2015-03-02 08:40:01ezio.melottisettype: enhancement
stage: needs patch
2014-11-07 15:22:44rbcollinssetmessages: + msg230812
2014-11-07 15:16:27r.david.murraysetnosy: + r.david.murray
messages: + msg230811
2014-11-07 10:00:09rbcollinscreate