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
1e95b6a2
Commit
1e95b6a2
authored
Nov 15, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup and added test filename to results.
parent
c606e57c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
19 deletions
+46
-19
__init__.py
__init__.py
+7
-0
__main__.py
__main__.py
+1
-3
runner.py
runner.py
+38
-16
No files found.
__init__.py
View file @
1e95b6a2
#
# Python unit test runner
#
# Author : Sander Mathijs van Veen <smvv@kompiler.org>
# License: GPL version 3, see also the file `LICENSE'.
#
from
runner
import
TextTestRunner
,
main
__all__
=
[
'TextTestRunner'
,
'main'
]
__main__.py
View file @
1e95b6a2
...
...
@@ -6,9 +6,7 @@
#
import
sys
import
unittest
from
testrunner
import
TextTestRunner
,
main
from
testrunner
import
main
if
len
(
sys
.
argv
)
<
2
:
print
'Usage: %s tests/test_COMPONENT.py'
%
sys
.
argv
[
0
]
...
...
runner.py
View file @
1e95b6a2
#
# Python unit test runner
#
# Author : Sander Mathijs van Veen <smvv@kompiler.org>
# License: GPL version 3, see also the file `LICENSE'.
#
import
os
import
sys
import
time
...
...
@@ -24,6 +30,7 @@ class TextTestRunner(unittest.TextTestRunner):
if
startTestRun
is
not
None
:
startTestRun
()
try
:
test
(
result
)
finally
:
...
...
@@ -35,11 +42,12 @@ class TextTestRunner(unittest.TextTestRunner):
timeTaken
=
stopTime
-
startTime
result
.
printErrors
()
run
=
result
.
testsRun
msg
=
'Ran %d test%s in %.3fs '
self
.
stream
.
write
(
msg
%
(
run
,
r
un
!=
1
and
's'
or
''
,
timeTaken
))
self
.
stream
.
write
(
'%s: %d test%s in %.3fs '
\
%
(
test
.
filename
,
result
.
testsRun
,
result
.
testsR
un
!=
1
and
's'
or
''
,
timeTaken
))
expectedFails
=
unexpectedSuccesses
=
skipped
=
0
try
:
results
=
map
(
len
,
(
result
.
expectedFailures
,
result
.
unexpectedSuccesses
,
...
...
@@ -59,12 +67,14 @@ class TextTestRunner(unittest.TextTestRunner):
self
.
stream
.
write
(
msg
)
failed
,
errored
=
map
(
len
,
(
result
.
failures
,
result
.
errors
))
if
failed
:
if
self
.
color
:
msg
=
'failures=
\
033
[1;31m%d
\
033
[1;m'
else
:
msg
=
'failures=%d'
infos
.
append
(
msg
%
failed
)
if
errored
:
if
self
.
color
:
msg
=
'errors=
\
033
[1;31m%d
\
033
[1;m'
...
...
@@ -76,6 +86,7 @@ class TextTestRunner(unittest.TextTestRunner):
msg
=
'
\
033
[0;32mOK
\
033
[0;m'
else
:
msg
=
'OK'
self
.
stream
.
write
(
msg
)
if
skipped
:
...
...
@@ -83,6 +94,7 @@ class TextTestRunner(unittest.TextTestRunner):
msg
=
'skipped=
\
033
[1;33m%d
\
033
[1;m'
else
:
msg
=
'skipped=%d'
infos
.
append
(
msg
%
skipped
)
if
expectedFails
:
...
...
@@ -99,28 +111,38 @@ class TextTestRunner(unittest.TextTestRunner):
return
result
def
main
(
tests
,
verbose
=
0
,
color
=
True
):
suit
es
=
[]
testcas
es
=
[]
# 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
try
:
module_name
=
os
.
path
.
splitext
(
testfile
)[
0
].
replace
(
'/'
,
'.'
)
module_obj
=
__import__
(
module_name
)
except
:
print
'testfile: '
,
testfile
print
'module_name:'
,
module_name
raise
# Start the test runner and display the results to stdout.
container
=
module_obj
.
__dict__
[
module_name
]
class_parts
=
module_name
[
5
:].
split
(
'_'
)
try
:
suite_name
=
module_name
.
split
(
'.'
)[
-
1
]
container
=
module_obj
.
__dict__
[
suite_name
]
except
:
print
'testfile: '
,
testfile
print
'module_name:'
,
module_name
print
'module_obj: '
,
module_obj
,
dir
(
module_obj
)
raise
# Convert lowercase, underscored suite name to Python class name.
class_parts
=
suite_name
[
5
:].
split
(
'_'
)
class_name
=
'Test'
+
''
.
join
([
p
.
capitalize
()
for
p
in
class_parts
])
testcase
=
container
.
__dict__
[
class_name
]
suit
es
+=
[
unittest
.
TestLoader
().
loadTestsFromTestCase
(
testcase
)]
testcas
es
+=
[
unittest
.
TestLoader
().
loadTestsFromTestCase
(
testcase
)]
# Create the text runner and execute the tests.
runner
=
TextTestRunner
(
verbosity
=
verbose
,
color
=
color
)
runner
.
run
(
unittest
.
TestSuite
(
suites
))
suite
=
unittest
.
TestSuite
(
testcases
)
suite
.
filename
=
testfile
runner
.
run
(
suite
)
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