Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5a9719d6
Commit
5a9719d6
authored
Sep 13, 2009
by
Michael Foord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unittest.TestLoader.loadTestsFromName honors the loader suiteClass attribute. Issue 6866.
parent
ee2df030
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
2 deletions
+46
-2
Doc/whatsnew/2.7.rst
Doc/whatsnew/2.7.rst
+3
-0
Lib/test/test_unittest.py
Lib/test/test_unittest.py
+41
-0
Lib/unittest/loader.py
Lib/unittest/loader.py
+2
-2
No files found.
Doc/whatsnew/2.7.rst
View file @
5a9719d6
...
@@ -509,6 +509,9 @@ changes, or look through the Subversion logs for all the details.
...
@@ -509,6 +509,9 @@ changes, or look through the Subversion logs for all the details.
(automatically pass or fail without checking decimal places) if the objects
(automatically pass or fail without checking decimal places) if the objects
are equal.
are equal.
* :meth:`loadTestsFromName` properly honors the ``suiteClass`` attribute of
the :class:`TestLoader`. (Fixed by Mark Roddy; :issue:`6866`.)
* A new hook, :meth:`addTypeEqualityFunc` takes a type object and a
* A new hook, :meth:`addTypeEqualityFunc` takes a type object and a
function. The :meth:`assertEqual` method will use the function
function. The :meth:`assertEqual` method will use the function
when both of the objects being compared are of the specified type.
when both of the objects being compared are of the specified type.
...
...
Lib/test/test_unittest.py
View file @
5a9719d6
...
@@ -554,6 +554,47 @@ class Test_TestLoader(TestCase):
...
@@ -554,6 +554,47 @@ class Test_TestLoader(TestCase):
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
testcase_1
])
self
.
assertEqual
(
list
(
suite
),
[
testcase_1
])
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a TestCase ... instance"
#*****************************************************************
#Override the suiteClass attribute to ensure that the suiteClass
#attribute is used
def
test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass
(
self
):
class
SubTestSuite
(
unittest
.
TestSuite
):
pass
m
=
types
.
ModuleType
(
'm'
)
testcase_1
=
unittest
.
FunctionTestCase
(
lambda
:
None
)
def
return_TestCase
():
return
testcase_1
m
.
return_TestCase
=
return_TestCase
loader
=
unittest
.
TestLoader
()
loader
.
suiteClass
=
SubTestSuite
suite
=
loader
.
loadTestsFromName
(
'return_TestCase'
,
m
)
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
testcase_1
])
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a test method within a test case class"
#*****************************************************************
#Override the suiteClass attribute to ensure that the suiteClass
#attribute is used
def
test_loadTestsFromName__relative_testmethod_ProperSuiteClass
(
self
):
class
SubTestSuite
(
unittest
.
TestSuite
):
pass
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
pass
m
.
testcase_1
=
MyTestCase
loader
=
unittest
.
TestLoader
()
loader
.
suiteClass
=
SubTestSuite
suite
=
loader
.
loadTestsFromName
(
'testcase_1.test'
,
m
)
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
MyTestCase
(
'test'
)])
# "The specifier name is a ``dotted name'' that may resolve ... to
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a TestCase or TestSuite instance"
# ... a callable object which returns a TestCase or TestSuite instance"
#
#
...
...
Lib/unittest/loader.py
View file @
5a9719d6
...
@@ -85,7 +85,7 @@ class TestLoader(object):
...
@@ -85,7 +85,7 @@ class TestLoader(object):
elif
(
isinstance
(
obj
,
types
.
UnboundMethodType
)
and
elif
(
isinstance
(
obj
,
types
.
UnboundMethodType
)
and
isinstance
(
parent
,
type
)
and
isinstance
(
parent
,
type
)
and
issubclass
(
parent
,
case
.
TestCase
)):
issubclass
(
parent
,
case
.
TestCase
)):
return
s
uite
.
TestSuite
([
parent
(
obj
.
__name__
)])
return
s
elf
.
suiteClass
([
parent
(
obj
.
__name__
)])
elif
isinstance
(
obj
,
suite
.
TestSuite
):
elif
isinstance
(
obj
,
suite
.
TestSuite
):
return
obj
return
obj
elif
hasattr
(
obj
,
'__call__'
):
elif
hasattr
(
obj
,
'__call__'
):
...
@@ -93,7 +93,7 @@ class TestLoader(object):
...
@@ -93,7 +93,7 @@ class TestLoader(object):
if
isinstance
(
test
,
suite
.
TestSuite
):
if
isinstance
(
test
,
suite
.
TestSuite
):
return
test
return
test
elif
isinstance
(
test
,
case
.
TestCase
):
elif
isinstance
(
test
,
case
.
TestCase
):
return
s
uite
.
TestSuite
([
test
])
return
s
elf
.
suiteClass
([
test
])
else
:
else
:
raise
TypeError
(
"calling %s returned %s, not a test"
%
raise
TypeError
(
"calling %s returned %s, not a test"
%
(
obj
,
test
))
(
obj
,
test
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment