classification
Title: python -m unittest ought to default to discovery
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: duncf, eli.bendersky, eric.araujo, michael.foord
Priority: normal Keywords: easy, patch

Created on 2010-11-20 17:55 by michael.foord, last changed 2010-11-22 10:51 by michael.foord. This issue is now closed.

Files
File name Uploaded Description Edit
issue10470.1.patch eli.bendersky, 2010-11-21 13:19
Messages (8)
msg121698 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-20 17:55
"python -m unittest" does nothing useful (runs 0 tests). It would be good to have it default to discovery, which removes the useless behaviour *and* makes the default invocation for test discovery shorter.
msg121761 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-20 20:34
The existing discover subcommand would enter the deprecation process, right?
msg121897 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-21 10:46
@Eric

No. "python -m unittest discover ..." will still be needed where you want to pass arguments to discovery ("python -m unittest ..." still has a different meaning where you pass arguments). All this will do is give the previously useless "python -m unittest" the same meaning as "python -m unittest discover".
msg121922 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2010-11-21 13:19
Submitting a complete patch file for this:

1. Modified Lib/unittest/main.py to implement the change
2. Modified Lib/unittest/test/test_program.py to make the tests pass without warnings from regrtest.py
3. Updated the documentation in Doc/library/unittest.rst
4. Updated Misc/NEWS
msg121973 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-21 20:11
Sorry for the late reply. I don't think the patch as provided is sufficient as it would interfere with people causing unittest.main() directly from a test module. Checking that TestProgram.loader is None is the way to detect we have been launched from the command line via "python -m unittest ..".
msg122000 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-21 21:33
Committed revision 86649.
msg122088 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2010-11-22 04:19
Michael,

I feared this might be the case. Without knowing the module deeply, it's not easy to be aware of all the possible paths, preconditions, and consequences (and tests obviously didn't catch that). A suggestion - maybe documenting these parts would allow you to get more meaningful help with the module. Or at least add the tests necessary to verify them.
msg122105 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-22 10:51
Eli - I quite agree. TestProgram is a *particularly* obscure part of unittest. A much better solution (well - both would be ideal) would be to refactor the code so that it isn't so obscure.

TestProgram is an artefact of unittest's history and should be a series of functions rather than a class.
History
Date User Action Args
2010-11-22 10:51:12michael.foordsetmessages: + msg122105
2010-11-22 04:19:21eli.benderskysetmessages: + msg122088
2010-11-21 21:33:03michael.foordsetstatus: open -> closed
resolution: accepted
messages: + msg122000

stage: needs patch -> resolved
2010-11-21 20:11:13michael.foordsetmessages: + msg121973
2010-11-21 13:22:23eli.benderskysetmessages: - msg121918
2010-11-21 13:22:19eli.benderskysetmessages: - msg121909
2010-11-21 13:19:36eli.benderskysetfiles: - unittest.test.test_program.diff
2010-11-21 13:19:33eli.benderskysetfiles: - unittest.main.diff
2010-11-21 13:19:25eli.benderskysetfiles: + issue10470.1.patch

messages: + msg121922
2010-11-21 12:49:19eli.benderskysetfiles: + unittest.test.test_program.diff

messages: + msg121918
2010-11-21 12:24:15eli.benderskysetfiles: + unittest.main.diff
keywords: + patch
messages: + msg121909
2010-11-21 12:23:00eli.benderskysetmessages: - msg121903
2010-11-21 11:16:54eli.benderskysetnosy: + eli.bendersky
messages: + msg121903
2010-11-21 10:46:05michael.foordsetmessages: + msg121897
2010-11-21 03:12:57duncfsetnosy: + duncf
2010-11-20 20:35:12eric.araujosetkeywords: + easy
stage: needs patch
2010-11-20 20:34:36eric.araujosetnosy: + eric.araujo
messages: + msg121761
2010-11-20 17:55:28michael.foordcreate