@@ -244,6 +244,10 @@ Command-line options
244
244
245
245
Show local variables in tracebacks.
246
246
247
+ .. cmdoption :: --durations N
248
+
249
+ Show the N slowest test cases (N=0 for all).
250
+
247
251
.. versionadded :: 3.2
248
252
The command-line options ``-b ``, ``-c `` and ``-f `` were added.
249
253
@@ -253,10 +257,12 @@ Command-line options
253
257
.. versionadded :: 3.7
254
258
The command-line option ``-k ``.
255
259
260
+ .. versionadded :: 3.12
261
+ The command-line option ``--durations ``.
262
+
256
263
The command line can also be used for test discovery, for running all of the
257
264
tests in a project or just a subset.
258
265
259
-
260
266
.. _unittest-test-discovery :
261
267
262
268
Test Discovery
@@ -2009,6 +2015,13 @@ Loading and running tests
2009
2015
A list containing :class: `TestCase ` instances that were marked as expected
2010
2016
failures, but succeeded.
2011
2017
2018
+ .. attribute :: collectedDurations
2019
+
2020
+ A list containing 2-tuples of :class: `TestCase ` instances and floats
2021
+ representing the elapsed time of each test which was run.
2022
+
2023
+ .. versionadded :: 3.12
2024
+
2012
2025
.. attribute :: shouldStop
2013
2026
2014
2027
Set to ``True `` when the execution of tests should stop by :meth: `stop `.
@@ -2160,14 +2173,27 @@ Loading and running tests
2160
2173
2161
2174
.. versionadded :: 3.4
2162
2175
2176
+ .. method :: addDuration(test, elapsed)
2177
+
2178
+ Called when the test case finishes. *elapsed * is the time represented in
2179
+ seconds, and it includes the execution of cleanup functions.
2180
+
2181
+ .. versionadded :: 3.12
2163
2182
2164
- .. class :: TextTestResult(stream, descriptions, verbosity)
2183
+ .. class :: TextTestResult(stream, descriptions, verbosity, *, durations=None )
2165
2184
2166
2185
A concrete implementation of :class: `TestResult ` used by the
2167
- :class: `TextTestRunner `.
2186
+ :class: `TextTestRunner `. Subclasses should accept ``**kwargs `` to ensure
2187
+ compatibility as the interface changes.
2168
2188
2169
2189
.. versionadded :: 3.2
2170
2190
2191
+ .. versionadded :: 3.12
2192
+ Added *durations * keyword argument.
2193
+
2194
+ .. versionchanged :: 3.12
2195
+ Subclasses should accept ``**kwargs `` to ensure compatibility as the
2196
+ interface changes.
2171
2197
2172
2198
.. data :: defaultTestLoader
2173
2199
@@ -2177,7 +2203,8 @@ Loading and running tests
2177
2203
2178
2204
2179
2205
.. class :: TextTestRunner(stream=None, descriptions=True, verbosity=1, failfast=False, \
2180
- buffer=False, resultclass=None, warnings=None, *, tb_locals=False)
2206
+ buffer=False, resultclass=None, warnings=None, *, \
2207
+ tb_locals=False, durations=None)
2181
2208
2182
2209
A basic test runner implementation that outputs results to a stream. If *stream *
2183
2210
is ``None ``, the default, :data: `sys.stderr ` is used as the output stream. This class
@@ -2195,14 +2222,17 @@ Loading and running tests
2195
2222
*warnings * to ``None ``.
2196
2223
2197
2224
.. versionchanged :: 3.2
2198
- Added the `` warnings `` argument .
2225
+ Added the * warnings * parameter .
2199
2226
2200
2227
.. versionchanged :: 3.2
2201
2228
The default stream is set to :data: `sys.stderr ` at instantiation time rather
2202
2229
than import time.
2203
2230
2204
2231
.. versionchanged :: 3.5
2205
- Added the tb_locals parameter.
2232
+ Added the *tb_locals * parameter.
2233
+
2234
+ .. versionchanged :: 3.12
2235
+ Added the *durations * parameter.
2206
2236
2207
2237
.. method :: _makeResult()
2208
2238
0 commit comments