Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pytestrunner
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pytestrunner
Commits
c606e57c
Commit
c606e57c
authored
Nov 01, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented simple color output and moved __main__ to main().
parent
87e29a31
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
42 deletions
+75
-42
__init__.py
__init__.py
+2
-2
__main__.py
__main__.py
+3
-27
runner.py
runner.py
+70
-13
No files found.
__init__.py
View file @
c606e57c
from
runner
import
TextTestRunner
from
runner
import
TextTestRunner
,
main
__all__
=
[
'TextTestRunner'
]
__all__
=
[
'TextTestRunner'
,
'main'
]
__main__.py
View file @
c606e57c
...
@@ -6,39 +6,15 @@
...
@@ -6,39 +6,15 @@
#
#
import
sys
import
sys
import
os
import
unittest
import
unittest
from
testrunner
import
TextTestRunner
from
testrunner
import
TextTestRunner
,
main
if
len
(
sys
.
argv
)
<
2
:
if
len
(
sys
.
argv
)
<
2
:
print
'Usage: %s tests/test_COMPONENT.py'
%
sys
.
argv
[
0
]
print
'Usage: %s tests/test_COMPONENT.py'
%
sys
.
argv
[
0
]
sys
.
exit
(
1
)
sys
.
exit
(
1
)
# TODO parse verbosity option '-v', given in argv.
# TODO parse verbosity option '-v', given in argv.
verbosity
=
0
verbose
=
0
suites
=
[]
# Dynamic load the requested module containing the test cases.
for
testfile
in
sys
.
argv
[
1
:]:
module_dir
,
module_file
=
os
.
path
.
split
(
testfile
)
module_name
,
module_ext
=
os
.
path
.
splitext
(
module_file
)
module_obj
=
__import__
(
module_dir
.
replace
(
'/'
,
'.'
),
fromlist
=
[
module_name
])
module_obj
.
__file__
=
testfile
globals
()[
module_name
]
=
module_obj
# Start the test runner and display the results to stdout.
container
=
module_obj
.
__dict__
[
module_name
]
class_parts
=
module_name
[
5
:].
split
(
'_'
)
class_name
=
'Test'
+
''
.
join
([
p
.
capitalize
()
for
p
in
class_parts
])
testcase
=
container
.
__dict__
[
class_name
]
suites
+=
[
unittest
.
TestLoader
().
loadTestsFromTestCase
(
testcase
)]
# Create the text runner and execute the tests.
main
(
sys
.
argv
[
1
:],
verbose
)
TextTestRunner
(
verbosity
=
verbosity
).
run
(
unittest
.
TestSuite
(
suites
))
runner.py
View file @
c606e57c
import
unittest
import
os
import
sys
import
time
import
time
import
unittest
class
TextTestRunner
(
unittest
.
TextTestRunner
):
class
TextTestRunner
(
unittest
.
TextTestRunner
):
...
@@ -7,6 +9,11 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -7,6 +9,11 @@ class TextTestRunner(unittest.TextTestRunner):
printed to stdout. The method ``run`` is modified and it's original source
printed to stdout. The method ``run`` is modified and it's original source
is in Python Standard Library's ``unittest`` module."""
is in Python Standard Library's ``unittest`` module."""
def
__init__
(
self
,
stream
=
sys
.
stderr
,
descriptions
=
True
,
verbosity
=
1
,
color
=
True
):
unittest
.
TextTestRunner
.
__init__
(
self
,
stream
,
descriptions
,
verbosity
)
self
.
color
=
color
def
run
(
self
,
test
):
def
run
(
self
,
test
):
"Run the given test case or test suite."
"Run the given test case or test suite."
result
=
self
.
_makeResult
()
result
=
self
.
_makeResult
()
...
@@ -29,8 +36,8 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -29,8 +36,8 @@ class TextTestRunner(unittest.TextTestRunner):
result
.
printErrors
()
result
.
printErrors
()
run
=
result
.
testsRun
run
=
result
.
testsRun
self
.
stream
.
write
(
"Ran %d test%s in %.3fs "
%
msg
=
'Ran %d test%s in %.3fs '
(
run
,
run
!=
1
and
"s"
or
""
,
timeTaken
))
self
.
stream
.
write
(
msg
%
(
run
,
run
!=
1
and
's'
or
''
,
timeTaken
))
expectedFails
=
unexpectedSuccesses
=
skipped
=
0
expectedFails
=
unexpectedSuccesses
=
skipped
=
0
try
:
try
:
...
@@ -45,25 +52,75 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -45,25 +52,75 @@ class TextTestRunner(unittest.TextTestRunner):
infos
=
[]
infos
=
[]
if
not
result
.
wasSuccessful
():
if
not
result
.
wasSuccessful
():
self
.
stream
.
write
(
"FAILED"
)
if
self
.
color
:
msg
=
'
\
033
[0;31mFAILED
\
033
[1;m'
else
:
msg
=
'FAILED'
self
.
stream
.
write
(
msg
)
failed
,
errored
=
map
(
len
,
(
result
.
failures
,
result
.
errors
))
failed
,
errored
=
map
(
len
,
(
result
.
failures
,
result
.
errors
))
if
failed
:
if
failed
:
infos
.
append
(
"failures=%d"
%
failed
)
if
self
.
color
:
msg
=
'failures=
\
033
[1;31m%d
\
033
[1;m'
else
:
msg
=
'failures=%d'
infos
.
append
(
msg
%
failed
)
if
errored
:
if
errored
:
infos
.
append
(
"errors=%d"
%
errored
)
if
self
.
color
:
msg
=
'errors=
\
033
[1;31m%d
\
033
[1;m'
else
:
msg
=
'errors=%d'
infos
.
append
(
msg
%
errored
)
else
:
else
:
self
.
stream
.
write
(
"OK"
)
if
self
.
color
:
msg
=
'
\
033
[0;32mOK
\
033
[0;m'
else
:
msg
=
'OK'
self
.
stream
.
write
(
msg
)
if
skipped
:
if
skipped
:
infos
.
append
(
"skipped=%d"
%
skipped
)
if
self
.
color
:
msg
=
'skipped=
\
033
[1;33m%d
\
033
[1;m'
else
:
msg
=
'skipped=%d'
infos
.
append
(
msg
%
skipped
)
if
expectedFails
:
if
expectedFails
:
infos
.
append
(
"expected failures=%d"
%
expectedFails
)
infos
.
append
(
'expected failures=%d'
%
expectedFails
)
if
unexpectedSuccesses
:
if
unexpectedSuccesses
:
infos
.
append
(
"unexpected successes=%d"
%
unexpectedSuccesses
)
infos
.
append
(
'unexpected successes=%d'
%
unexpectedSuccesses
)
if
infos
:
if
infos
:
self
.
stream
.
writeln
(
" (%s)"
%
(
", "
.
join
(
infos
),))
self
.
stream
.
writeln
(
' (%s)'
%
(
', '
.
join
(
infos
),))
else
:
else
:
self
.
stream
.
write
(
"
\
n
"
)
self
.
stream
.
write
(
'
\
n
'
)
return
result
return
result
def
main
(
tests
,
verbose
=
0
,
color
=
True
):
suites
=
[]
# Dynamic load the requested module containing the test cases.
for
testfile
in
tests
:
module_dir
,
module_file
=
os
.
path
.
split
(
testfile
)
module_name
,
module_ext
=
os
.
path
.
splitext
(
module_file
)
# XXX: this looks really hacky, so cleanup is necessary.
module_obj
=
__import__
(
module_dir
.
replace
(
'/'
,
'.'
),
fromlist
=
[
module_name
])
module_obj
.
__file__
=
testfile
globals
()[
module_name
]
=
module_obj
# Start the test runner and display the results to stdout.
container
=
module_obj
.
__dict__
[
module_name
]
class_parts
=
module_name
[
5
:].
split
(
'_'
)
class_name
=
'Test'
+
''
.
join
([
p
.
capitalize
()
for
p
in
class_parts
])
testcase
=
container
.
__dict__
[
class_name
]
suites
+=
[
unittest
.
TestLoader
().
loadTestsFromTestCase
(
testcase
)]
# Create the text runner and execute the tests.
runner
=
TextTestRunner
(
verbosity
=
verbose
,
color
=
color
)
runner
.
run
(
unittest
.
TestSuite
(
suites
))
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