Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
RustPython/Lib/unittest/result.py at release · RustPython/RustPython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
RustPython
/
RustPython
Public
Notifications
You must be signed in to change notification settings
Fork
1.5k
Star
22.3k
Code
Issues
295
Pull requests
99
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
release
Breadcrumbs
RustPython
/
Lib
/
unittest
/
result.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
216 lines (181 loc) · 7.27 KB
release
Breadcrumbs
RustPython
/
Lib
/
unittest
/
result.py
Copy path
Top
File metadata and controls
Code
Blame
216 lines (181 loc) · 7.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
"""Test result object"""
import
io
import
sys
import
traceback
from
.
import
util
from
functools
import
wraps
__unittest
=
True
def
failfast
(
method
):
@
wraps
(
method
)
def
inner
(
self
,
*
args
,
**
kw
):
if
getattr
(
self
,
'failfast'
,
False
):
self
.
stop
()
return
method
(
self
,
*
args
,
**
kw
)
return
inner
STDOUT_LINE
=
'
\n
Stdout:
\n
%s'
STDERR_LINE
=
'
\n
Stderr:
\n
%s'
class
TestResult
(
object
):
"""Holder for test result information.
Test results are automatically managed by the TestCase and TestSuite
classes, and do not need to be explicitly manipulated by writers of tests.
Each instance holds the total number of tests run, and collections of
failures and errors that occurred among those test runs. The collections
contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
formatted traceback of the error that occurred.
"""
_previousTestClass
=
None
_testRunEntered
=
False
_moduleSetUpFailed
=
False
def
__init__
(
self
,
stream
=
None
,
descriptions
=
None
,
verbosity
=
None
):
self
.
failfast
=
False
self
.
failures
=
[]
self
.
errors
=
[]
self
.
testsRun
=
0
self
.
skipped
=
[]
self
.
expectedFailures
=
[]
self
.
unexpectedSuccesses
=
[]
self
.
shouldStop
=
False
self
.
buffer
=
False
self
.
tb_locals
=
False
self
.
_stdout_buffer
=
None
self
.
_stderr_buffer
=
None
self
.
_original_stdout
=
sys
.
stdout
self
.
_original_stderr
=
sys
.
stderr
self
.
_mirrorOutput
=
False
def
printErrors
(
self
):
"Called by TestRunner after test run"
def
startTest
(
self
,
test
):
"Called when the given test is about to be run"
self
.
testsRun
+=
1
self
.
_mirrorOutput
=
False
self
.
_setupStdout
()
def
_setupStdout
(
self
):
if
self
.
buffer
:
if
self
.
_stderr_buffer
is
None
:
self
.
_stderr_buffer
=
io
.
StringIO
()
self
.
_stdout_buffer
=
io
.
StringIO
()
sys
.
stdout
=
self
.
_stdout_buffer
sys
.
stderr
=
self
.
_stderr_buffer
def
startTestRun
(
self
):
"""Called once before any tests are executed.
See startTest for a method called before each test.
"""
def
stopTest
(
self
,
test
):
"""Called when the given test has been run"""
self
.
_restoreStdout
()
self
.
_mirrorOutput
=
False
def
_restoreStdout
(
self
):
if
self
.
buffer
:
if
self
.
_mirrorOutput
:
output
=
sys
.
stdout
.
getvalue
()
error
=
sys
.
stderr
.
getvalue
()
if
output
:
if
not
output
.
endswith
(
'
\n
'
):
output
+=
'
\n
'
self
.
_original_stdout
.
write
(
STDOUT_LINE
%
output
)
if
error
:
if
not
error
.
endswith
(
'
\n
'
):
error
+=
'
\n
'
self
.
_original_stderr
.
write
(
STDERR_LINE
%
error
)
sys
.
stdout
=
self
.
_original_stdout
sys
.
stderr
=
self
.
_original_stderr
self
.
_stdout_buffer
.
seek
(
0
)
self
.
_stdout_buffer
.
truncate
()
self
.
_stderr_buffer
.
seek
(
0
)
self
.
_stderr_buffer
.
truncate
()
def
stopTestRun
(
self
):
"""Called once after all tests are executed.
See stopTest for a method called after each test.
"""
@
failfast
def
addError
(
self
,
test
,
err
):
"""Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().
"""
self
.
errors
.
append
((
test
,
self
.
_exc_info_to_string
(
err
,
test
)))
self
.
_mirrorOutput
=
True
@
failfast
def
addFailure
(
self
,
test
,
err
):
"""Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info()."""
self
.
failures
.
append
((
test
,
self
.
_exc_info_to_string
(
err
,
test
)))
self
.
_mirrorOutput
=
True
def
addSubTest
(
self
,
test
,
subtest
,
err
):
"""Called at the end of a subtest.
'err' is None if the subtest ended successfully, otherwise it's a
tuple of values as returned by sys.exc_info().
"""
# By default, we don't do anything with successful subtests, but
# more sophisticated test results might want to record them.
if
err
is
not
None
:
if
getattr
(
self
,
'failfast'
,
False
):
self
.
stop
()
if
issubclass
(
err
[
0
],
test
.
failureException
):
errors
=
self
.
failures
else
:
errors
=
self
.
errors
errors
.
append
((
subtest
,
self
.
_exc_info_to_string
(
err
,
test
)))
self
.
_mirrorOutput
=
True
def
addSuccess
(
self
,
test
):
"Called when a test has completed successfully"
pass
def
addSkip
(
self
,
test
,
reason
):
"""Called when a test is skipped."""
self
.
skipped
.
append
((
test
,
reason
))
def
addExpectedFailure
(
self
,
test
,
err
):
"""Called when an expected failure/error occurred."""
self
.
expectedFailures
.
append
(
(
test
,
self
.
_exc_info_to_string
(
err
,
test
)))
@
failfast
def
addUnexpectedSuccess
(
self
,
test
):
"""Called when a test was expected to fail, but succeed."""
self
.
unexpectedSuccesses
.
append
(
test
)
def
wasSuccessful
(
self
):
"""Tells whether or not this result was a success."""
# The hasattr check is for test_result's OldResult test. That
# way this method works on objects that lack the attribute.
# (where would such result intances come from? old stored pickles?)
return
((
len
(
self
.
failures
)
==
len
(
self
.
errors
)
==
0
)
and
(
not
hasattr
(
self
,
'unexpectedSuccesses'
)
or
len
(
self
.
unexpectedSuccesses
)
==
0
))
def
stop
(
self
):
"""Indicates that the tests should be aborted."""
self
.
shouldStop
=
True
def
_exc_info_to_string
(
self
,
err
,
test
):
"""Converts a sys.exc_info()-style tuple of values into a string."""
exctype
,
value
,
tb
=
err
# Skip test runner traceback levels
while
tb
and
self
.
_is_relevant_tb_level
(
tb
):
tb
=
tb
.
tb_next
if
exctype
is
test
.
failureException
:
# Skip assert*() traceback levels
length
=
self
.
_count_relevant_tb_levels
(
tb
)
else
:
length
=
None
tb_e
=
traceback
.
TracebackException
(
exctype
,
value
,
tb
,
limit
=
length
,
capture_locals
=
self
.
tb_locals
)
msgLines
=
list
(
tb_e
.
format
())
if
self
.
buffer
:
output
=
sys
.
stdout
.
getvalue
()
error
=
sys
.
stderr
.
getvalue
()
if
output
:
if
not
output
.
endswith
(
'
\n
'
):
output
+=
'
\n
'
msgLines
.
append
(
STDOUT_LINE
%
output
)
if
error
:
if
not
error
.
endswith
(
'
\n
'
):
error
+=
'
\n
'
msgLines
.
append
(
STDERR_LINE
%
error
)
return
''
.
join
(
msgLines
)
def
_is_relevant_tb_level
(
self
,
tb
):
return
'__unittest'
in
tb
.
tb_frame
.
f_globals
def
_count_relevant_tb_levels
(
self
,
tb
):
length
=
0
while
tb
and
not
self
.
_is_relevant_tb_level
(
tb
):
length
+=
1
tb
=
tb
.
tb_next
return
length
def
__repr__
(
self
):
return
(
"<%s run=%i errors=%i failures=%i>"
%
(
util
.
strclass
(
self
.
__class__
),
self
.
testsRun
,
len
(
self
.
errors
),
len
(
self
.
failures
)))
You can’t perform that action at this time.