This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest discovery needs better explanation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: blokeley, docs@python, eric.araujo, ezio.melotti, michael.foord, r.david.murray
Priority: normal Keywords: patch

Created on 2011-02-23 11:42 by blokeley, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue11298_default.patch blokeley, 2011-03-08 10:01 issue11298_default patch review
issue11298_py3.2.patch blokeley, 2011-03-08 10:03 issue11298 py3.2 patch review
issue11298_py2.7.patch r.david.murray, 2011-03-15 23:15 review
Messages (24)
msg129176 - (view) Author: blokeley (blokeley) Date: 2011-02-23 11:42
`python -m unittest discover` caught me out. 

I had a test module called `test-foo.py` and no test was loaded.

When I renamed to `test_foo.py` it worked.

The documentation says "For a project’s tests to be compatible with test discovery they must all be importable".

I didn't realise that test-foo would not be importable. Could the documentation say "For a project’s tests to be compatible with test discovery they must all be importable, so ensure that the module names are valid Python identifiers."

Stackoverflow question is here: http://stackoverflow.com/questions/5088960/python-unittest-discovery-does-not-discover-tests
msg129179 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-02-23 12:06
Sounds like a good change to the docs. Care to provide a patch?
msg129189 - (view) Author: blokeley (blokeley) Date: 2011-02-23 13:18
Will do but I haven't submitted a patch before and it's impossible to tell from python.org/dev whether to use the svn or hg repositories.

If possible, please just let me know the URL of the hg repository against which I should make the patch (I don't currently have an svn client).

I tried using hg convert on http://svn.python.org/projects/python/branches/py3k but my company firewall blocked that from working (too many HTTP requests per minute).
msg129190 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-02-23 13:30
http://code.python.org/hg/branches/py3k/
msg129197 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-02-23 14:29
Thanks blokely, looks good. Needs applying to 2.7 / 3.2 and 3.3 branches.
msg129209 - (view) Author: blokeley (blokeley) Date: 2011-02-23 15:40
Added release2.7-maint patch.
msg129210 - (view) Author: blokeley (blokeley) Date: 2011-02-23 15:46
Added release2.7-maint patch.
msg129211 - (view) Author: blokeley (blokeley) Date: 2011-02-23 15:49
Added release3.2-maint patch.

I created the patches by cloning the corresponding hg repo from http://code.python.org/hg If this is the wrong thing to do, let me know.

I have no idea where the 3.3 branch is. Please advise.
msg129212 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-02-23 15:50
Hey, blokeley the same patch will apply cleanly against 3.2 / 3.3 so no worries.
msg129441 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-02-25 22:00
I’m not sure what’s best between the proposed addition and a link to the definition of module/importable.  I think that programmers should know that not all file names are valid module names, so I wouldn’t want us to copy the definition all over the docs.  Thoughts?
msg129444 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-02-25 22:15
What about something like
"""
In order to be compatible with test discovery, all the test modules must be importable from the top level directory of the project (in other words, they must be part of the project :ref:`package <tut-packages>`, and their name must be valid :ref:`identifiers <identifiers>`).
"""
?
msg129489 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-02-26 01:30
I like that.  Is it true that test discovery requires tests to be in a Python package, as opposed to top-level modules?
msg129540 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-02-26 13:03
No, tests as top level modules work fine too. Importability is the only requirement. (Projects themselves are not typically packages but contain packages - so the wording needs to change slightly but I like the rest.)
msg130184 - (view) Author: blokeley (blokeley) Date: 2011-03-06 18:51
Is this wording correct?

"""
In order to be compatible with test discovery, all of the test modules must be importable from the top level directory of the project (in other words, they must be part of the project :ref:`package <tut-packages>` or directly importable :ref:`modules <tut-modules>`, and their names must be valid :ref:`identifiers <identifiers>`).
"""

If this wording is acceptable, I can provide patches.
msg130271 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-03-07 18:06
Sounds good to me.
msg130272 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-07 18:11
I find there are some redundancy and perfectible phrasing.  Here’s my rewrite:

In order to be compatible with test discovery, all of the test files must be :ref:`modules <tut-modules>` or :ref:`packages <tut-packages>` importable from the top-level directory of the project (this means that their filenames must be valid :ref:`identifiers <identifiers>`).
msg130309 - (view) Author: blokeley (blokeley) Date: 2011-03-08 10:01
Patch for py3k (default branch).
msg130310 - (view) Author: blokeley (blokeley) Date: 2011-03-08 10:02
Patch for 2.7 branch.
msg130311 - (view) Author: blokeley (blokeley) Date: 2011-03-08 10:03
Patch for 3.2 branch.
This is the first time I've submitted patches so I hope the format is OK. If I could have submitted 1 patch to apply to 2.7, 3.2 and py3k at the same time let me know.
Hope this helps.
msg130330 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-08 14:18
#11298: Improve the unittest discovery explanation.
http://hg.python.org/cpython/rev/bbf8a8a1af17
msg130332 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-08 14:51
#11298: merge from 3.2.
http://hg.python.org/cpython/rev/fa23f323d747
msg130334 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-08 15:10
#11298: Improve the unittest discovery explanation.
http://hg.python.org/cpython/rev/88b5a93b1725
msg130336 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-08 15:13
Fixed on 2.7, 3.2 and py3k, thanks for the patch!
msg131063 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-15 23:15
Drat, I accidentally deleted the patch file.  Reattaching.
History
Date User Action Args
2022-04-11 14:57:13adminsetgithub: 55507
2011-03-15 23:15:38r.david.murraysetfiles: + issue11298_py2.7.patch
nosy: + r.david.murray
messages: + msg131063

2011-03-15 23:09:29r.david.murraysetfiles: - issue11298_py2.7.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
2011-03-08 15:13:13ezio.melottisetstatus: open -> closed
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130336

resolution: fixed
stage: patch review -> resolved
2011-03-08 15:10:15ezio.melottisetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130334
2011-03-08 14:51:04ezio.melottisetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130332
2011-03-08 14:18:32ezio.melottisetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130330
2011-03-08 11:28:32ezio.melottisetassignee: docs@python -> ezio.melotti
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
stage: patch review
2011-03-08 10:03:52blokeleysetfiles: + issue11298_py3.2.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130311
2011-03-08 10:02:13blokeleysetfiles: + issue11298_py2.7.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130310
2011-03-08 10:01:33blokeleysetfiles: + issue11298_default.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130309
2011-03-08 10:00:13blokeleysetfiles: - py3.2-maint_rev9895_issue11298.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
2011-03-08 10:00:08blokeleysetfiles: - py2.7-maint_rev45852_issue11298.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
2011-03-08 10:00:01blokeleysetfiles: - py3k_rev9921_issue11298.patch
nosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
2011-03-07 18:11:39eric.araujosetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130272
2011-03-07 18:06:23michael.foordsetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130271
2011-03-06 18:51:07blokeleysetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg130184
2011-02-26 13:04:00michael.foordsetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg129540
2011-02-26 01:30:35eric.araujosetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg129489
2011-02-25 22:15:28ezio.melottisetnosy: ezio.melotti, eric.araujo, michael.foord, docs@python, blokeley
messages: + msg129444
2011-02-25 22:00:00eric.araujosetnosy: + eric.araujo
messages: + msg129441
2011-02-23 15:50:32michael.foordsetnosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129212
2011-02-23 15:49:23blokeleysetfiles: + py3.2-maint_rev9895_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129211
2011-02-23 15:46:13blokeleysetfiles: + py2.7-maint_rev45852_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129210
2011-02-23 15:41:19blokeleysetfiles: - py2.7-maint_rev45852_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
2011-02-23 15:40:34blokeleysetfiles: + py2.7-maint_rev45852_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129209
2011-02-23 14:29:09michael.foordsetnosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129197
2011-02-23 14:28:00blokeleysetfiles: + py3k_rev9921_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
2011-02-23 14:24:26blokeleysetfiles: - py3k_rev9921_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
2011-02-23 14:23:14blokeleysetfiles: + py3k_rev9921_issue11298.patch
nosy: ezio.melotti, michael.foord, docs@python, blokeley
keywords: + patch
2011-02-23 13:30:40ezio.melottisetnosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129190
2011-02-23 13:18:01blokeleysetnosy: ezio.melotti, michael.foord, docs@python, blokeley
messages: + msg129189
2011-02-23 12:08:31ezio.melottisetnosy: + ezio.melotti
2011-02-23 12:06:14michael.foordsetnosy: + michael.foord
messages: + msg129179
2011-02-23 11:42:53blokeleycreate