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
a29dd1e0
Commit
a29dd1e0
authored
Dec 19, 2010
by
Michael Foord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 10611. SystemExit should not cause a unittest test run to exit.
parent
46c689ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
4 deletions
+66
-4
Lib/unittest/case.py
Lib/unittest/case.py
+12
-4
Lib/unittest/test/test_case.py
Lib/unittest/test/test_case.py
+52
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/unittest/case.py
View file @
a29dd1e0
...
@@ -311,11 +311,15 @@ class TestCase(object):
...
@@ -311,11 +311,15 @@ class TestCase(object):
self
.
setUp
()
self
.
setUp
()
except
SkipTest
as
e
:
except
SkipTest
as
e
:
self
.
_addSkip
(
result
,
str
(
e
))
self
.
_addSkip
(
result
,
str
(
e
))
except
Exception
:
except
KeyboardInterrupt
:
raise
except
:
result
.
addError
(
self
,
sys
.
exc_info
())
result
.
addError
(
self
,
sys
.
exc_info
())
else
:
else
:
try
:
try
:
testMethod
()
testMethod
()
except
KeyboardInterrupt
:
raise
except
self
.
failureException
:
except
self
.
failureException
:
result
.
addFailure
(
self
,
sys
.
exc_info
())
result
.
addFailure
(
self
,
sys
.
exc_info
())
except
_ExpectedFailure
as
e
:
except
_ExpectedFailure
as
e
:
...
@@ -336,14 +340,16 @@ class TestCase(object):
...
@@ -336,14 +340,16 @@ class TestCase(object):
result
.
addFailure
(
self
,
sys
.
exc_info
())
result
.
addFailure
(
self
,
sys
.
exc_info
())
except
SkipTest
as
e
:
except
SkipTest
as
e
:
self
.
_addSkip
(
result
,
str
(
e
))
self
.
_addSkip
(
result
,
str
(
e
))
except
Exception
:
except
:
result
.
addError
(
self
,
sys
.
exc_info
())
result
.
addError
(
self
,
sys
.
exc_info
())
else
:
else
:
success
=
True
success
=
True
try
:
try
:
self
.
tearDown
()
self
.
tearDown
()
except
Exception
:
except
KeyboardInterrupt
:
raise
except
:
result
.
addError
(
self
,
sys
.
exc_info
())
result
.
addError
(
self
,
sys
.
exc_info
())
success
=
False
success
=
False
...
@@ -367,7 +373,9 @@ class TestCase(object):
...
@@ -367,7 +373,9 @@ class TestCase(object):
function
,
args
,
kwargs
=
self
.
_cleanups
.
pop
(
-
1
)
function
,
args
,
kwargs
=
self
.
_cleanups
.
pop
(
-
1
)
try
:
try
:
function
(
*
args
,
**
kwargs
)
function
(
*
args
,
**
kwargs
)
except
Exception
:
except
KeyboardInterrupt
:
raise
except
:
ok
=
False
ok
=
False
result
.
addError
(
self
,
sys
.
exc_info
())
result
.
addError
(
self
,
sys
.
exc_info
())
return
ok
return
ok
...
...
Lib/unittest/test/test_case.py
View file @
a29dd1e0
...
@@ -999,6 +999,58 @@ test case
...
@@ -999,6 +999,58 @@ test case
# This shouldn't blow up
# This shouldn't blow up
deepcopy
(
test
)
deepcopy
(
test
)
def
testKeyboardInterrupt
(
self
):
def
_raise
(
self
=
None
):
raise
KeyboardInterrupt
def
nothing
(
self
):
pass
class
Test1
(
unittest
.
TestCase
):
test_something
=
_raise
class
Test2
(
unittest
.
TestCase
):
setUp
=
_raise
test_something
=
nothing
class
Test3
(
unittest
.
TestCase
):
test_something
=
nothing
tearDown
=
_raise
class
Test4
(
unittest
.
TestCase
):
def
test_something
(
self
):
self
.
addCleanup
(
_raise
)
for
klass
in
(
Test1
,
Test2
,
Test3
,
Test4
):
with
self
.
assertRaises
(
KeyboardInterrupt
):
klass
(
'test_something'
).
run
()
def
testSystemExit
(
self
):
def
_raise
(
self
=
None
):
raise
SystemExit
def
nothing
(
self
):
pass
class
Test1
(
unittest
.
TestCase
):
test_something
=
_raise
class
Test2
(
unittest
.
TestCase
):
setUp
=
_raise
test_something
=
nothing
class
Test3
(
unittest
.
TestCase
):
test_something
=
nothing
tearDown
=
_raise
class
Test4
(
unittest
.
TestCase
):
def
test_something
(
self
):
self
.
addCleanup
(
_raise
)
for
klass
in
(
Test1
,
Test2
,
Test3
,
Test4
):
result
=
unittest
.
TestResult
()
klass
(
'test_something'
).
run
(
result
)
self
.
assertEqual
(
len
(
result
.
errors
),
1
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS
View file @
a29dd1e0
...
@@ -22,6 +22,8 @@ Core and Builtins
...
@@ -22,6 +22,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10611: SystemExit should not cause a unittest test run to exit.
- Issue #6791: Limit header line length (to 65535 bytes) in http.client,
- Issue #6791: Limit header line length (to 65535 bytes) in http.client,
to avoid denial of services from the other party.
to avoid denial of services from the other party.
...
...
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