classification
Title: unittest discovery should use self.testLoader
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: chris.jerdonek, ezio.melotti, michael.foord, python-dev
Priority: normal Keywords:

Created on 2013-01-27 10:11 by chris.jerdonek, last changed 2013-02-11 17:11 by chris.jerdonek. This issue is now closed.

Messages (9)
msg180755 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013-01-27 10:11
The _do_discovery() method of unittest.TestProgram:

    def _do_discovery(self, argv, Loader=loader.TestLoader):

(from http://hg.python.org/cpython/file/2cf89e2e6247/Lib/unittest/main.py#l222 )

should be using self.testLoader instead of loader.TestLoader.  It's not consistent for some parts of TestProgram to use loader.TestLoader and other parts to use the testLoader passed in via the constructor.
msg180850 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-01-28 11:38
I think you're correct - although I wonder if *anyone*, *ever* will be helped by the change. :-)
msg180851 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013-01-28 11:47
I will at least! :)  I noticed the issue after trying to use unittest test discovery with a custom loader.  Fortunately, there is at least this work-around (though it relies on an implementation detail):

    class MyTestProgram(unittest.TestProgram):

        # Override because of issue #17052.
        def _do_discovery(self, argv, Loader=None):
            if Loader is None:
                Loader = lambda: self.testLoader
            super(TestPizza, self)._do_discovery(argv, Loader=Loader)
msg181863 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-11 00:28
New changeset b53b029895df by Michael Foord in branch 'default':
Merge. Closes issue 17052.
http://hg.python.org/cpython/rev/b53b029895df
msg181867 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013-02-11 01:26
Michael, was this implemented correctly?  Loader should be a callable (e.g. a class), but self.testLoader is an instance (it defaults to loader.defaultTestLoader, which equals loader.TestLoader()):

http://hg.python.org/cpython/file/b53b029895df/Lib/unittest/loader.py#l302
msg181872 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013-02-11 04:15
+- Issue #17502: unittest discovery should use self.testLoader.

Also, this should read Issue #17052.
msg181891 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2013-02-11 10:26
I think you're right! Thanks.
msg181893 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-11 13:39
New changeset ece0a2e6b08e by Michael Foord in branch '2.7':
Correction to issue 17052 fix
http://hg.python.org/cpython/rev/ece0a2e6b08e

New changeset 867763eb6985 by Michael Foord in branch '3.2':
Correction to issue 17052 fix
http://hg.python.org/cpython/rev/867763eb6985

New changeset a79650aacb43 by Michael Foord in branch 'default':
Merge. Closes issue 17052.
http://hg.python.org/cpython/rev/a79650aacb43
msg181912 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2013-02-11 17:11
Thanks a lot for taking care of this issue, Michael.
History
Date User Action Args
2013-02-11 17:11:52chris.jerdoneksetmessages: + msg181912
2013-02-11 13:39:58python-devsetstatus: open -> closed
resolution: fixed
messages: + msg181893

stage: commit review -> resolved
2013-02-11 10:26:26michael.foordsetstatus: closed -> open
assignee: michael.foord
resolution: fixed -> (no value)
messages: + msg181891
2013-02-11 04:15:34chris.jerdoneksetmessages: + msg181872
2013-02-11 01:26:51chris.jerdoneksetmessages: + msg181867
stage: resolved -> commit review
2013-02-11 00:28:23python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg181863

resolution: fixed
stage: test needed -> resolved
2013-01-28 11:47:28chris.jerdoneksetmessages: + msg180851
2013-01-28 11:38:10michael.foordsetmessages: + msg180850
2013-01-27 10:11:51chris.jerdonekcreate