[issue11298] unittest discovery needs better explanation
New submission from blokeley <blokeley@gmail.com>: `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-no... ---------- assignee: docs@python components: Documentation messages: 129176 nosy: blokeley, docs@python priority: normal severity: normal status: open title: unittest discovery needs better explanation type: behavior versions: Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Michael Foord <michael@voidspace.org.uk> added the comment: Sounds like a good change to the docs. Care to provide a patch? ---------- nosy: +michael.foord _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: 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). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: http://code.python.org/hg/branches/py3k/ ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: ---------- keywords: +patch Added file: http://bugs.python.org/file20862/py3k_rev9921_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: Removed file: http://bugs.python.org/file20862/py3k_rev9921_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: Added file: http://bugs.python.org/file20863/py3k_rev9921_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Michael Foord <michael@voidspace.org.uk> added the comment: Thanks blokely, looks good. Needs applying to 2.7 / 3.2 and 3.3 branches. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: Added release2.7-maint patch. ---------- Added file: http://bugs.python.org/file20864/py2.7-maint_rev45852_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: Removed file: http://bugs.python.org/file20864/py2.7-maint_rev45852_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: Added release2.7-maint patch. ---------- Added file: http://bugs.python.org/file20865/py2.7-maint_rev45852_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: 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. ---------- Added file: http://bugs.python.org/file20866/py3.2-maint_rev9895_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Michael Foord <michael@voidspace.org.uk> added the comment: Hey, blokeley the same patch will apply cleanly against 3.2 / 3.3 so no worries. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: 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? ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: 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>`). """ ? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: I like that. Is it true that test discovery requires tests to be in a Python package, as opposed to top-level modules? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Michael Foord <michael@voidspace.org.uk> added the comment: 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.) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Michael Foord <michael@voidspace.org.uk> added the comment: Sounds good to me. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: 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>`). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: Removed file: http://bugs.python.org/file20863/py3k_rev9921_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: Removed file: http://bugs.python.org/file20865/py2.7-maint_rev45852_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by blokeley <blokeley@gmail.com>: Removed file: http://bugs.python.org/file20866/py3.2-maint_rev9895_issue11298.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: Patch for py3k (default branch). ---------- Added file: http://bugs.python.org/file21042/issue11298_default.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: Patch for 2.7 branch. ---------- Added file: http://bugs.python.org/file21043/issue11298_py2.7.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
blokeley <blokeley@gmail.com> added the comment: 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. ---------- Added file: http://bugs.python.org/file21044/issue11298_py3.2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- assignee: docs@python -> ezio.melotti stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: #11298: Improve the unittest discovery explanation. http://hg.python.org/cpython/rev/bbf8a8a1af17 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: #11298: merge from 3.2. http://hg.python.org/cpython/rev/fa23f323d747 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: #11298: Improve the unittest discovery explanation. http://hg.python.org/cpython/rev/88b5a93b1725 ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Ezio Melotti <ezio.melotti@gmail.com> added the comment: Fixed on 2.7, 3.2 and py3k, thanks for the patch! ---------- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
Changes by R. David Murray <rdmurray@bitdance.com>: Removed file: http://bugs.python.org/file21043/issue11298_py2.7.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: Drat, I accidentally deleted the patch file. Reattaching. ---------- nosy: +r.david.murray Added file: http://bugs.python.org/file21234/issue11298_py2.7.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11298> _______________________________________
participants (5)
-
blokeley
-
Ezio Melotti
-
Michael Foord
-
R. David Murray
-
Éric Araujo