[New-bugs-announce] [issue6866] TestLoader.loadTestsFromName does not use suiteClass attribute to create TestSuite instances

Mark Roddy report at bugs.python.org
Tue Sep 8 22:03:50 CEST 2009


New submission from Mark Roddy <markroddy at gmail.com>:

The TestLoader class in unittest.py has an attribute 'suiteClass' that 
is used to create instances of TestSuite object(s) in the process of 
loading tests.  If it is desired to subclass the TestSuite class then 
consumers may set this attribute on a TestLoader object in order to 
override what TestSuite class gets instantiated (a pythonic version of 
the factory method pattern).  

However, the loadTestsFromName() on the TestLoader class does not use 
this attribute to create TestSuite instances, and instead has a hard 
coded reference to the unittest.TestSuite class.  This results in the 
base class being created instead of a possibly desired subclass that 
has been specified via this attribute.  

Solution for this issue is to change the loadTestsFromName() method to 
use the suiteClass attribute when creating TestSuite objects instead 
using a reference to the TestSuite class.  Included is a patch that 
implements this behavior as well as two additional test for the 
test_unittest.py file which expose this issue if run against an 
unpatched version of unittest.

----------
components: Library (Lib)
files: unittest.patch
keywords: patch
messages: 92427
nosy: MarkRoddy
severity: normal
status: open
title: TestLoader.loadTestsFromName does not use suiteClass attribute to create TestSuite instances
type: behavior
versions: Python 2.6, Python 3.0
Added file: http://bugs.python.org/file14864/unittest.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6866>
_______________________________________


More information about the New-bugs-announce mailing list