Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pytestrunner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pytestrunner
Commits
1e95b6a2
Commit
1e95b6a2
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Code cleanup and added test filename to results.
parent
c606e57c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__init__.py
+7
-0
7 additions, 0 deletions
__init__.py
__main__.py
+1
-3
1 addition, 3 deletions
__main__.py
runner.py
+38
-16
38 additions, 16 deletions
runner.py
with
46 additions
and
19 deletions
__init__.py
+
7
−
0
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
'
]
This diff is collapsed.
Click to expand it.
__main__.py
+
1
−
3
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
]
...
...
This diff is collapsed.
Click to expand it.
runner.py
+
38
−
16
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment