homepage

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: Let unittest.TestProgram()'s defaultTest argument be a list
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: chris.jerdonek, ezio.melotti, michael.foord, nailor, petri.lehtinen, python-dev
Priority: normal Keywords: easy, patch

Created on 2012年06月22日 08:25 by chris.jerdonek, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue15132_py3.patch nailor, 2012年10月23日 13:04
issue15132_py3_v2.patch nailor, 2012年11月25日 12:41
issue15132_py3_no_convert.patch nailor, 2012年11月26日 00:00
Messages (13)
msg163386 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012年06月22日 08:25
It would be nice if unittest.TestProgram(), aka unittest.main(), allowed one to set self.testNames by programmatically passing in a list of test names.
Currently, unittest.main() almost allows this: the constructor sets self.testNames to a 1-tuple containing the value of the defaultTest argument. But defaultTest can only be a string, not a list of test names.
A way around this is to pass the test names explicitly via the argv argument, but this seems less elegant as a programmatic API. Moreover, this approach isn't equivalent because test names passed via argv first get passed to a _convert_names() function.
It seems like it would be a natural and simple change to enhance unittest.TestProgram() to accept not just a name but also a list of names for the defaultTest argument. Thanks.
msg173609 - (view) Author: Jyrki Pulliainen (nailor) * Date: 2012年10月23日 13:02
Added a patch for passing everything of not type basestring to tuple constructor and assigns that to testnames.
msg173628 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012年10月23日 18:14
Thanks for the patch.
- self.testNames = (self.defaultTest,)
+ if isinstance(self.defaultTest, str):
+ self.testNames = (self.defaultTest,)
+ else:
+ self.testNames = tuple(self.defaultTest)
Is there any reason this is a tuple instead of a list? A list would be more flexible. In contrast, the _convert_names() function used in this line of code sets self.testNames to be a list of test names:
 self.testNames = _convert_names(args)
(from http://hg.python.org/cpython/file/8576bf1c0302/Lib/unittest/main.py#l161 )
By the way, this can only go into Python 3.4 as it is an enhancement.
msg176346 - (view) Author: Jyrki Pulliainen (nailor) * Date: 2012年11月25日 12:41
I rebased this change on top of 3.4 and in case of an iterable argument it now uses the _convert_names function to convert it to a list of test names.
msg176381 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012年11月25日 18:18
To clarify, I didn't say that _convert_names() should be used. I was just noting that it returns a list.
msg176391 - (view) Author: Jyrki Pulliainen (nailor) * Date: 2012年11月25日 23:59
Yeah, I added the convert names call mostly to make the behavior the same as with passing things from command line.
However, then we should probably wrap the case of str argument to _convert_name and the conversion behavior might be bit too implicit.
I added another patch which does not do the convert_names, but just makes it a list
msg182783 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013年02月23日 17:56
New changeset 4e2bfe6b227a by Petri Lehtinen in branch 'default':
Issue #15132: Allow a list for the defaultTest argument of unittest.TestProgram
http://hg.python.org/cpython/rev/4e2bfe6b227a 
msg182784 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2013年02月23日 17:57
Applied, thanks!
msg182831 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013年02月23日 23:16
Thanks, Jyrki and Petri. I just noticed that a "Changed in version" should probably be added at the end of this section:
http://docs.python.org/dev/library/unittest.html#unittest.main
*defaultTest* should probably also be documented in the text (it currently appears only in the documentation signature), though this part of my comment need not be done as part of this issue.
msg182832 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013年02月23日 23:17
I can take care of the Changed in version.
msg182836 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013年02月23日 23:47
New changeset 4285d13fd3dc by Chris Jerdonek in branch 'default':
Add a "Changed in version" to the docs for issue #15132.
http://hg.python.org/cpython/rev/4285d13fd3dc 
msg182840 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013年02月24日 00:15
> *defaultTest* should probably also be documented in the text
I created issue 17282 for this.
msg207181 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014年01月02日 18:44
New changeset 1bbf8c263d3c by R David Murray in branch 'default':
Merge and update #17282: Document unittest.main defaultTest argument.
http://hg.python.org/cpython/rev/1bbf8c263d3c 
History
Date User Action Args
2022年04月11日 14:57:31adminsetgithub: 59337
2014年01月02日 18:44:50python-devsetmessages: + msg207181
2013年02月24日 00:15:59chris.jerdoneksetmessages: + msg182840
2013年02月23日 23:47:28python-devsetmessages: + msg182836
2013年02月23日 23:17:41chris.jerdoneksetmessages: + msg182832
2013年02月23日 23:16:14chris.jerdoneksetmessages: + msg182831
2013年02月23日 17:57:04petri.lehtinensetstatus: open -> closed
resolution: fixed
messages: + msg182784

stage: resolved
2013年02月23日 17:56:31python-devsetnosy: + python-dev
messages: + msg182783
2012年11月26日 00:00:25nailorsetfiles: + issue15132_py3_no_convert.patch
2012年11月25日 23:59:56nailorsetmessages: + msg176391
2012年11月25日 18:18:05chris.jerdoneksetmessages: + msg176381
2012年11月25日 12:42:11nailorsetfiles: - issue15132_py2.patch
2012年11月25日 12:41:13nailorsetfiles: + issue15132_py3_v2.patch

messages: + msg176346
2012年10月24日 22:06:20michael.foordsetassignee: michael.foord
2012年10月23日 18:14:45chris.jerdoneksetmessages: + msg173628
versions: + Python 3.4, - Python 3.3
2012年10月23日 13:04:44nailorsetfiles: + issue15132_py3.patch
2012年10月23日 13:02:03nailorsetfiles: + issue15132_py2.patch

nosy: + nailor
messages: + msg173609

keywords: + patch
2012年10月23日 10:02:13petri.lehtinensetnosy: + petri.lehtinen
2012年06月22日 16:09:59ezio.melottisetnosy: + ezio.melotti, michael.foord
2012年06月22日 08:25:30chris.jerdonekcreate

AltStyle によって変換されたページ (->オリジナル) /