-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let unittest.TestProgram()'s defaultTest argument be a list #59337
Comments
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. |
Added a patch for passing everything of not type basestring to tuple constructor and assigns that to testnames. |
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. |
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. |
To clarify, I didn't say that _convert_names() should be used. I was just noting that it returns a list. |
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 |
New changeset 4e2bfe6b227a by Petri Lehtinen in branch 'default': |
Applied, thanks! |
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. |
I can take care of the Changed in version. |
New changeset 4285d13fd3dc by Chris Jerdonek in branch 'default': |
I created bpo-17282 for this. |
New changeset 1bbf8c263d3c by R David Murray in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: