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
bb1e3f1e
Commit
bb1e3f1e
authored
Sep 08, 2014
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A few tweaks for issue16662 based on feedback from Robert Collins.
parent
d78742a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
38 deletions
+46
-38
Lib/unittest/loader.py
Lib/unittest/loader.py
+5
-2
Lib/unittest/test/test_loader.py
Lib/unittest/test/test_loader.py
+41
-36
No files found.
Lib/unittest/loader.py
View file @
bb1e3f1e
...
...
@@ -79,12 +79,15 @@ class TestLoader(object):
# use_load_tests argument. For backward compatibility, we still
# accept the argument (which can also be the first position) but we
# ignore it and issue a deprecation warning if it's present.
if
len
(
args
)
==
1
or
'use_load_tests'
in
kws
:
if
len
(
args
)
>
0
or
'use_load_tests'
in
kws
:
warnings
.
warn
(
'use_load_tests is deprecated and ignored'
,
DeprecationWarning
)
kws
.
pop
(
'use_load_tests'
,
None
)
if
len
(
args
)
>
1
:
raise
TypeError
(
'loadTestsFromModule() takes 1 positional argument but {} were given'
.
format
(
len
(
args
)))
# Complain about the number of arguments, but don't forget the
# required `module` argument.
complaint
=
len
(
args
)
+
1
raise
TypeError
(
'loadTestsFromModule() takes 1 positional argument but {} were given'
.
format
(
complaint
))
if
len
(
kws
)
!=
0
:
# Since the keyword arguments are unsorted (see PEP 468), just
# pick the alphabetically sorted first argument to complain about,
...
...
Lib/unittest/test/test_loader.py
View file @
bb1e3f1e
...
...
@@ -196,23 +196,23 @@ class Test_TestLoader(unittest.TestCase):
@
warningregistry
def
test_loadTestsFromModule__use_load_tests_deprecated_positional
(
self
):
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
pass
m
.
testcase_1
=
MyTestCase
load_tests_args
=
[]
def
load_tests
(
loader
,
tests
,
pattern
):
self
.
assertIsInstance
(
tests
,
unittest
.
TestSuite
)
load_tests_args
.
extend
((
loader
,
tests
,
pattern
))
return
tests
m
.
load_tests
=
load_tests
# The method still works.
loader
=
unittest
.
TestLoader
()
# use_load_tests=True as a positional argument.
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
'always'
)
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
pass
m
.
testcase_1
=
MyTestCase
load_tests_args
=
[]
def
load_tests
(
loader
,
tests
,
pattern
):
self
.
assertIsInstance
(
tests
,
unittest
.
TestSuite
)
load_tests_args
.
extend
((
loader
,
tests
,
pattern
))
return
tests
m
.
load_tests
=
load_tests
# The method still works.
loader
=
unittest
.
TestLoader
()
# use_load_tests=True as a positional argument.
suite
=
loader
.
loadTestsFromModule
(
m
,
False
)
self
.
assertIsInstance
(
suite
,
unittest
.
TestSuite
)
# load_tests was still called because use_load_tests is deprecated
...
...
@@ -225,22 +225,22 @@ class Test_TestLoader(unittest.TestCase):
@
warningregistry
def
test_loadTestsFromModule__use_load_tests_deprecated_keyword
(
self
):
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
pass
m
.
testcase_1
=
MyTestCase
load_tests_args
=
[]
def
load_tests
(
loader
,
tests
,
pattern
):
self
.
assertIsInstance
(
tests
,
unittest
.
TestSuite
)
load_tests_args
.
extend
((
loader
,
tests
,
pattern
))
return
tests
m
.
load_tests
=
load_tests
# The method still works.
loader
=
unittest
.
TestLoader
()
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
'always'
)
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
pass
m
.
testcase_1
=
MyTestCase
load_tests_args
=
[]
def
load_tests
(
loader
,
tests
,
pattern
):
self
.
assertIsInstance
(
tests
,
unittest
.
TestSuite
)
load_tests_args
.
extend
((
loader
,
tests
,
pattern
))
return
tests
m
.
load_tests
=
load_tests
# The method still works.
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromModule
(
m
,
use_load_tests
=
False
)
self
.
assertIsInstance
(
suite
,
unittest
.
TestSuite
)
# load_tests was still called because use_load_tests is deprecated
...
...
@@ -251,6 +251,7 @@ class Test_TestLoader(unittest.TestCase):
self
.
assertEqual
(
str
(
w
[
-
1
].
message
),
'use_load_tests is deprecated and ignored'
)
@
warningregistry
def
test_loadTestsFromModule__too_many_positional_args
(
self
):
m
=
types
.
ModuleType
(
'm'
)
class
MyTestCase
(
unittest
.
TestCase
):
...
...
@@ -265,14 +266,18 @@ class Test_TestLoader(unittest.TestCase):
return
tests
m
.
load_tests
=
load_tests
loader
=
unittest
.
TestLoader
()
with
self
.
assertRaises
(
TypeError
)
as
cm
:
with
self
.
assertRaises
(
TypeError
)
as
cm
,
\
warnings
.
catch_warning
(
record
=
True
)
as
w
:
loader
.
loadTestsFromModule
(
m
,
False
,
'testme.*'
)
self
.
assertEqual
(
type
(
cm
.
exception
),
TypeError
)
# The error message names the first bad argument alphabetically,
# however use_load_tests (which sorts first) is ignored.
self
.
assertEqual
(
str
(
cm
.
exception
),
'loadTestsFromModule() takes 1 positional argument but 2 were given'
)
# We still got the deprecation warning.
self
.
assertIs
(
w
[
-
1
].
category
,
DeprecationWarning
)
self
.
assertEqual
(
str
(
w
[
-
1
].
message
),
'use_load_tests is deprecated and ignored'
)
# We also got a TypeError for too many positional arguments.
self
.
assertEqual
(
type
(
cm
.
exception
),
TypeError
)
self
.
assertEqual
(
str
(
cm
.
exception
),
'loadTestsFromModule() takes 1 positional argument but 3 were given'
)
@
warningregistry
def
test_loadTestsFromModule__use_load_tests_other_bad_keyword
(
self
):
...
...
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