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
26938f2d
Commit
26938f2d
authored
Apr 11, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#14971: Use class method name, not function.__name__, during unittest discovery.
parent
8e677015
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
Lib/unittest/loader.py
Lib/unittest/loader.py
+1
-1
Lib/unittest/test/test_loader.py
Lib/unittest/test/test_loader.py
+16
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/loader.py
View file @
26938f2d
...
...
@@ -111,7 +111,7 @@ class TestLoader(object):
elif
(
isinstance
(
obj
,
types
.
FunctionType
)
and
isinstance
(
parent
,
type
)
and
issubclass
(
parent
,
case
.
TestCase
)):
name
=
obj
.
__name__
name
=
parts
[
-
1
]
inst
=
parent
(
name
)
# static methods follow a different path
if
not
isinstance
(
getattr
(
inst
,
name
),
types
.
FunctionType
):
...
...
Lib/unittest/test/test_loader.py
View file @
26938f2d
...
...
@@ -806,6 +806,22 @@ class Test_TestLoader(unittest.TestCase):
ref_suite
=
unittest
.
TestSuite
([
MyTestCase
(
'test'
)])
self
.
assertEqual
(
list
(
suite
),
[
ref_suite
])
# #14971: Make sure the dotted name resolution works even if the actual
# function doesn't have the same name as is used to find it.
def
test_loadTestsFromName__function_with_different_name_than_method
(
self
):
# lambdas have the name '<lambda>'.
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
test
=
lambda
:
1
m
.
testcase_1
=
MyTestCase
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'testcase_1.test'
],
m
)
self
.
assertIsInstance
(
suite
,
loader
.
suiteClass
)
ref_suite
=
unittest
.
TestSuite
([
MyTestCase
(
'test'
)])
self
.
assertEqual
(
list
(
suite
),
[
ref_suite
])
# "The specifier name is a ``dotted name'' that may resolve ... to ... a
# test method within a test case class"
#
...
...
Misc/NEWS
View file @
26938f2d
...
...
@@ -23,6 +23,9 @@ Core and Builtins
Library
-------
-
Issue
#
14971
:
unittest
test
discovery
no
longer
gets
confused
when
a
function
has
a
different
__name__
than
its
name
in
the
TestCase
class
dictionary
.
-
Issue
#
17678
:
Fix
DeprecationWarning
in
the
http
/
cookiejar
.
py
by
changing
the
usage
of
get_origin_req_host
()
to
origin_req_host
.
...
...
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