Skip to content
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

Closed
cjerdonek opened this issue Jun 22, 2012 · 13 comments
Closed

Let unittest.TestProgram()'s defaultTest argument be a list #59337

cjerdonek opened this issue Jun 22, 2012 · 13 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@cjerdonek
Copy link
Member

BPO 15132
Nosy @ezio-melotti, @voidspace, @cjerdonek, @akheron
Files
  • issue15132_py3.patch
  • issue15132_py3_v2.patch
  • issue15132_py3_no_convert.patch
  • 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:

    assignee = 'https://github.com/voidspace'
    closed_at = <Date 2013-02-23.17:57:04.745>
    created_at = <Date 2012-06-22.08:25:30.012>
    labels = ['easy', 'type-feature', 'library']
    title = "Let unittest.TestProgram()'s defaultTest argument be a list"
    updated_at = <Date 2014-01-02.18:44:50.726>
    user = 'https://github.com/cjerdonek'

    bugs.python.org fields:

    activity = <Date 2014-01-02.18:44:50.726>
    actor = 'python-dev'
    assignee = 'michael.foord'
    closed = True
    closed_date = <Date 2013-02-23.17:57:04.745>
    closer = 'petri.lehtinen'
    components = ['Library (Lib)']
    creation = <Date 2012-06-22.08:25:30.012>
    creator = 'chris.jerdonek'
    dependencies = []
    files = ['27682', '28112', '28126']
    hgrepos = []
    issue_num = 15132
    keywords = ['patch', 'easy']
    message_count = 13.0
    messages = ['163386', '173609', '173628', '176346', '176381', '176391', '182783', '182784', '182831', '182832', '182836', '182840', '207181']
    nosy_count = 6.0
    nosy_names = ['ezio.melotti', 'michael.foord', 'chris.jerdonek', 'nailor', 'python-dev', 'petri.lehtinen']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue15132'
    versions = ['Python 3.4']

    @cjerdonek
    Copy link
    Member Author

    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.

    @cjerdonek cjerdonek added stdlib Python modules in the Lib dir easy type-feature A feature request or enhancement labels Jun 22, 2012
    @nailor
    Copy link
    Mannequin

    nailor mannequin commented Oct 23, 2012

    Added a patch for passing everything of not type basestring to tuple constructor and assigns that to testnames.

    @cjerdonek
    Copy link
    Member Author

    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.

    @voidspace voidspace self-assigned this Oct 24, 2012
    @nailor
    Copy link
    Mannequin

    nailor mannequin commented Nov 25, 2012

    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.

    @cjerdonek
    Copy link
    Member Author

    To clarify, I didn't say that _convert_names() should be used. I was just noting that it returns a list.

    @nailor
    Copy link
    Mannequin

    nailor mannequin commented Nov 25, 2012

    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

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 23, 2013

    New changeset 4e2bfe6b227a by Petri Lehtinen in branch 'default':
    Issue bpo-15132: Allow a list for the defaultTest argument of unittest.TestProgram
    http://hg.python.org/cpython/rev/4e2bfe6b227a

    @akheron
    Copy link
    Member

    akheron commented Feb 23, 2013

    Applied, thanks!

    @akheron akheron closed this as completed Feb 23, 2013
    @cjerdonek
    Copy link
    Member Author

    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.

    @cjerdonek
    Copy link
    Member Author

    I can take care of the Changed in version.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 23, 2013

    New changeset 4285d13fd3dc by Chris Jerdonek in branch 'default':
    Add a "Changed in version" to the docs for issue bpo-15132.
    http://hg.python.org/cpython/rev/4285d13fd3dc

    @cjerdonek
    Copy link
    Member Author

    *defaultTest* should probably also be documented in the text

    I created bpo-17282 for this.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 2, 2014

    New changeset 1bbf8c263d3c by R David Murray in branch 'default':
    Merge and update bpo-17282: Document unittest.main defaultTest argument.
    http://hg.python.org/cpython/rev/1bbf8c263d3c

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants