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
80928857
Commit
80928857
authored
Mar 07, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #787789: allow to pass custom TestRunner instances to unittest's
main() function.
parent
3f4d877b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
5 deletions
+20
-5
Doc/lib/libunittest.tex
Doc/lib/libunittest.tex
+5
-1
Lib/unittest.py
Lib/unittest.py
+12
-4
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libunittest.tex
View file @
80928857
...
...
@@ -290,6 +290,7 @@ Often, many small test cases will use the same fixture. In this case,
we would end up subclassing
\class
{
SimpleWidgetTestCase
}
into many
small one-method classes such as
\class
{
DefaultWidgetSizeTestCase
}
. This is time-consuming and
discouraging, so in the same vein as JUnit,
\module
{
unittest
}
provides
a simpler mechanism:
...
...
@@ -540,7 +541,7 @@ easier.}
\begin{funcdesc}
{
main
}{
\optional
{
module
\optional
{
,
defaultTest
\optional
{
, argv
\optional
{
,
testRunner
\optional
{
, test
Runn
er
}}}}}}
testRunner
\optional
{
, test
Load
er
}}}}}}
A command-line program that runs a set of tests; this is primarily
for making test modules conveniently executable. The simplest use
for this function is to include the following line at the end of a
...
...
@@ -550,6 +551,9 @@ easier.}
if
__
name
__
== '
__
main
__
':
unittest.main()
\end{verbatim}
The
\var
{
testRunner
}
argument can either be a test runner class or
an already created instance of it.
\end{funcdesc}
In some cases, the existing tests may have been written using the
...
...
Lib/unittest.py
View file @
80928857
...
...
@@ -776,7 +776,8 @@ Examples:
in MyTestCase
"""
def
__init__
(
self
,
module
=
'__main__'
,
defaultTest
=
None
,
argv
=
None
,
testRunner
=
None
,
testLoader
=
defaultTestLoader
):
argv
=
None
,
testRunner
=
TextTestRunner
,
testLoader
=
defaultTestLoader
):
if
type
(
module
)
==
type
(
''
):
self
.
module
=
__import__
(
module
)
for
part
in
module
.
split
(
'.'
)[
1
:]:
...
...
@@ -826,9 +827,16 @@ Examples:
self
.
module
)
def
runTests
(
self
):
if
self
.
testRunner
is
None
:
self
.
testRunner
=
TextTestRunner
(
verbosity
=
self
.
verbosity
)
result
=
self
.
testRunner
.
run
(
self
.
test
)
if
isinstance
(
self
.
testRunner
,
(
type
,
types
.
ClassType
)):
try
:
testRunner
=
self
.
testRunner
(
verbosity
=
self
.
verbosity
)
except
TypeError
:
# didn't accept the verbosity argument
testRunner
=
self
.
testRunner
()
else
:
# it is assumed to be a TestRunner instance
testRunner
=
self
.
testRunner
result
=
testRunner
.
run
(
self
.
test
)
sys
.
exit
(
not
result
.
wasSuccessful
())
main
=
TestProgram
...
...
Misc/NEWS
View file @
80928857
...
...
@@ -152,6 +152,9 @@ Core and builtins
Library
-------
- Patch #787789: allow to pass custom TestRunner instances to unittest'
s
main
()
function
.
-
Patches
#
1550273
,
#
1550272
:
fix
a
few
bugs
in
unittest
and
add
a
comprehensive
test
suite
for
the
module
.
...
...
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