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
from
runner
import
TextTestRunner
,
main
__all__
=
[
'TextTestRunner'
,
'main'
]
__all__
=
[
'TextTestRunner'
,
'main'
]
__main__.py
View file @
1e95b6a2
...
@@ -6,9 +6,7 @@
...
@@ -6,9 +6,7 @@
#
#
import
sys
import
sys
import
unittest
from
testrunner
import
main
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
]
...
...
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
os
import
sys
import
sys
import
time
import
time
...
@@ -24,6 +30,7 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -24,6 +30,7 @@ class TextTestRunner(unittest.TextTestRunner):
if
startTestRun
is
not
None
:
if
startTestRun
is
not
None
:
startTestRun
()
startTestRun
()
try
:
try
:
test
(
result
)
test
(
result
)
finally
:
finally
:
...
@@ -35,11 +42,12 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -35,11 +42,12 @@ class TextTestRunner(unittest.TextTestRunner):
timeTaken
=
stopTime
-
startTime
timeTaken
=
stopTime
-
startTime
result
.
printErrors
()
result
.
printErrors
()
run
=
result
.
testsRun
self
.
stream
.
write
(
'%s: %d test%s in %.3fs '
\
msg
=
'Ran %d test%s in %.3fs '
%
(
test
.
filename
,
result
.
testsRun
,
self
.
stream
.
write
(
msg
%
(
run
,
r
un
!=
1
and
's'
or
''
,
timeTaken
))
result
.
testsR
un
!=
1
and
's'
or
''
,
timeTaken
))
expectedFails
=
unexpectedSuccesses
=
skipped
=
0
expectedFails
=
unexpectedSuccesses
=
skipped
=
0
try
:
try
:
results
=
map
(
len
,
(
result
.
expectedFailures
,
results
=
map
(
len
,
(
result
.
expectedFailures
,
result
.
unexpectedSuccesses
,
result
.
unexpectedSuccesses
,
...
@@ -59,12 +67,14 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -59,12 +67,14 @@ class TextTestRunner(unittest.TextTestRunner):
self
.
stream
.
write
(
msg
)
self
.
stream
.
write
(
msg
)
failed
,
errored
=
map
(
len
,
(
result
.
failures
,
result
.
errors
))
failed
,
errored
=
map
(
len
,
(
result
.
failures
,
result
.
errors
))
if
failed
:
if
failed
:
if
self
.
color
:
if
self
.
color
:
msg
=
'failures=
\
033
[1;31m%d
\
033
[1;m'
msg
=
'failures=
\
033
[1;31m%d
\
033
[1;m'
else
:
else
:
msg
=
'failures=%d'
msg
=
'failures=%d'
infos
.
append
(
msg
%
failed
)
infos
.
append
(
msg
%
failed
)
if
errored
:
if
errored
:
if
self
.
color
:
if
self
.
color
:
msg
=
'errors=
\
033
[1;31m%d
\
033
[1;m'
msg
=
'errors=
\
033
[1;31m%d
\
033
[1;m'
...
@@ -76,6 +86,7 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -76,6 +86,7 @@ class TextTestRunner(unittest.TextTestRunner):
msg
=
'
\
033
[0;32mOK
\
033
[0;m'
msg
=
'
\
033
[0;32mOK
\
033
[0;m'
else
:
else
:
msg
=
'OK'
msg
=
'OK'
self
.
stream
.
write
(
msg
)
self
.
stream
.
write
(
msg
)
if
skipped
:
if
skipped
:
...
@@ -83,6 +94,7 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -83,6 +94,7 @@ class TextTestRunner(unittest.TextTestRunner):
msg
=
'skipped=
\
033
[1;33m%d
\
033
[1;m'
msg
=
'skipped=
\
033
[1;33m%d
\
033
[1;m'
else
:
else
:
msg
=
'skipped=%d'
msg
=
'skipped=%d'
infos
.
append
(
msg
%
skipped
)
infos
.
append
(
msg
%
skipped
)
if
expectedFails
:
if
expectedFails
:
...
@@ -99,28 +111,38 @@ class TextTestRunner(unittest.TextTestRunner):
...
@@ -99,28 +111,38 @@ class TextTestRunner(unittest.TextTestRunner):
return
result
return
result
def
main
(
tests
,
verbose
=
0
,
color
=
True
):
def
main
(
tests
,
verbose
=
0
,
color
=
True
):
suit
es
=
[]
testcas
es
=
[]
# Dynamic load the requested module containing the test cases.
# Dynamic load the requested module containing the test cases.
for
testfile
in
tests
:
for
testfile
in
tests
:
module_dir
,
module_file
=
os
.
path
.
split
(
testfile
)
try
:
module_name
,
module_ext
=
os
.
path
.
splitext
(
module_file
)
module_name
=
os
.
path
.
splitext
(
testfile
)[
0
].
replace
(
'/'
,
'.'
)
module_obj
=
__import__
(
module_name
)
# XXX: this looks really hacky, so cleanup is necessary.
except
:
module_obj
=
__import__
(
module_dir
.
replace
(
'/'
,
'.'
),
print
'testfile: '
,
testfile
fromlist
=
[
module_name
])
print
'module_name:'
,
module_name
module_obj
.
__file__
=
testfile
raise
globals
()[
module_name
]
=
module_obj
# Start the test runner and display the results to stdout.
# Start the test runner and display the results to stdout.
container
=
module_obj
.
__dict__
[
module_name
]
try
:
class_parts
=
module_name
[
5
:].
split
(
'_'
)
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
])
class_name
=
'Test'
+
''
.
join
([
p
.
capitalize
()
for
p
in
class_parts
])
testcase
=
container
.
__dict__
[
class_name
]
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.
# Create the text runner and execute the tests.
runner
=
TextTestRunner
(
verbosity
=
verbose
,
color
=
color
)
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