[Patches] [ python-Patches-787789 ] unittest.py: Custom TestRunners and --verbose

SourceForge.net noreply at sourceforge.net
Wed Mar 7 10:21:39 CET 2007


Patches item #787789, was opened at 2003-08-13 03:31
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=787789&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.3
>Status: Closed
>Resolution: Accepted
Priority: 3
Private: No
Submitted By: Matthew Barnes (mfbarnes)
Assigned to: Steve Purcell (purcell)
Summary: unittest.py: Custom TestRunners and --verbose

Initial Comment:
The unittest.TestProgram class accepts a "--verbose"
command-line argument.  But the setting only gets
applied if the testRunner argument to
unittest.TestProgram.__init__ is None.  There is no
clean way of creating a custom TestRunner class and
passing it to unittest.TestProgram such that the
correct verbosity is picked up.

This patch slightly alters the interface to
unittest.TestProgram.__init__ by allowing a class to be
passed as the testRunner argument (defaulting to
TextTestRunner instead of None).  Then the runTests
method of unittest.TestProgram checks whether
self.testRunner is a class, and if so creates an
instance of it, passing the correct verbosity setting
to the TestRunner class' __init__ method.

The patch should still allow a custom TestRunner class
_instance_ to be passed to unittest.TestProgram.__init__.

----------------------------------------------------------------------

>Comment By: Georg Brandl (gbrandl)
Date: 2007-03-07 09:21

Message:
Logged In: YES 
user_id=849994
Originator: NO

Thanks for the patch, committed a variant as rev. 54201.

----------------------------------------------------------------------

Comment By: Steve Purcell (purcell)
Date: 2003-09-10 16:20

Message:
Logged In: YES 
user_id=21477

I can see your point, but this requres every test runner to accept the 
'verbosity' keyword argument. I'm worried that this will break a large 
number of custom test runners. 
 
Another approach might be to change TextTestRunner so that 'verbosity' 
is an instance attribute that is set by TestProgram after the test runner 
instance is created. Then existing custom test runners will not break, 
unless they already have a 'verbosity' attribute, which is unlikely. 
 
I'll bear this patch in mind; I'm looking at a few pending minor changes 
to the module, and this area is one that I'm covering. 

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=787789&group_id=5470


More information about the Patches mailing list