blob: c32b93dae7966c4e1927abb1b910f38954baadd4 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`test` --- Regression tests package for Python
3===================================================
4
5.. module:: test
6 :synopsis: Regression tests package containing the testing suite for Python.
7.. sectionauthor:: Brett Cannon <brett@python.org>
8
Brett Cannon9ae2cb72010-07-23 12:07:27 +00009.. note::
10 The :mod:`test` package is meant for internal use by Python only. It is
11 documented for the benefit of the core developers of Python. Any use of
12 this package outside of Python's standard library is discouraged as code
13 mentioned here can change or be removed without notice between releases of
14 Python.
15
Georg Brandl8ec7f652007-08-15 14:28:01 +000016
17The :mod:`test` package contains all regression tests for Python as well as the
Serhiy Storchakaa694e092017-04-30 11:36:58 +030018modules :mod:`test.support` and :mod:`test.regrtest`.
19:mod:`test.support` is used to enhance your tests while
Georg Brandl8ec7f652007-08-15 14:28:01 +000020:mod:`test.regrtest` drives the testing suite.
21
22Each module in the :mod:`test` package whose name starts with ``test_`` is a
23testing suite for a specific module or feature. All new tests should be written
24using the :mod:`unittest` or :mod:`doctest` module. Some older tests are
25written using a "traditional" testing style that compares output printed to
26``sys.stdout``; this style of test is considered deprecated.
27
28
29.. seealso::
30
31 Module :mod:`unittest`
32 Writing PyUnit regression tests.
33
34 Module :mod:`doctest`
35 Tests embedded in documentation strings.
36
37
38.. _writing-tests:
39
40Writing Unit Tests for the :mod:`test` package
41----------------------------------------------
42
Georg Brandl8ec7f652007-08-15 14:28:01 +000043It is preferred that tests that use the :mod:`unittest` module follow a few
44guidelines. One is to name the test module by starting it with ``test_`` and end
45it with the name of the module being tested. The test methods in the test module
46should start with ``test_`` and end with a description of what the method is
47testing. This is needed so that the methods are recognized by the test driver as
48test methods. Also, no documentation string for the method should be included. A
49comment (such as ``# Tests function returns only True or False``) should be used
50to provide documentation for test methods. This is done because documentation
51strings get printed out if they exist and thus what test is being run is not
52stated.
53
54A basic boilerplate is often used::
55
56 import unittest
Serhiy Storchakaa694e092017-04-30 11:36:58 +030057 from test import support
Georg Brandl8ec7f652007-08-15 14:28:01 +000058
59 class MyTestCase1(unittest.TestCase):
60
61 # Only use setUp() and tearDown() if necessary
62
63 def setUp(self):
64 ... code to execute in preparation for tests ...
65
66 def tearDown(self):
67 ... code to execute to clean up after tests ...
68
69 def test_feature_one(self):
70 # Test feature one.
71 ... testing code ...
72
73 def test_feature_two(self):
74 # Test feature two.
75 ... testing code ...
76
77 ... more test methods ...
78
79 class MyTestCase2(unittest.TestCase):
80 ... same structure as MyTestCase1 ...
81
82 ... more test classes ...
83
84 def test_main():
Serhiy Storchakaa694e092017-04-30 11:36:58 +030085 support.run_unittest(MyTestCase1,
86 MyTestCase2,
87 ... list other tests ...
88 )
Georg Brandl8ec7f652007-08-15 14:28:01 +000089
90 if __name__ == '__main__':
91 test_main()
92
93This boilerplate code allows the testing suite to be run by :mod:`test.regrtest`
94as well as on its own as a script.
95
96The goal for regression testing is to try to break code. This leads to a few
97guidelines to be followed:
98
99* The testing suite should exercise all classes, functions, and constants. This
Florent Xicluna73588542010-03-18 19:51:47 +0000100 includes not just the external API that is to be presented to the outside
101 world but also "private" code.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000102
103* Whitebox testing (examining the code being tested when the tests are being
104 written) is preferred. Blackbox testing (testing only the published user
Florent Xicluna73588542010-03-18 19:51:47 +0000105 interface) is not complete enough to make sure all boundary and edge cases
106 are tested.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000107
108* Make sure all possible values are tested including invalid ones. This makes
Florent Xicluna73588542010-03-18 19:51:47 +0000109 sure that not only all valid values are acceptable but also that improper
110 values are handled correctly.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000111
112* Exhaust as many code paths as possible. Test where branching occurs and thus
113 tailor input to make sure as many different paths through the code are taken.
114
115* Add an explicit test for any bugs discovered for the tested code. This will
116 make sure that the error does not crop up again if the code is changed in the
117 future.
118
119* Make sure to clean up after your tests (such as close and remove all temporary
120 files).
121
122* If a test is dependent on a specific condition of the operating system then
123 verify the condition already exists before attempting the test.
124
125* Import as few modules as possible and do it as soon as possible. This
126 minimizes external dependencies of tests and also minimizes possible anomalous
127 behavior from side-effects of importing a module.
128
129* Try to maximize code reuse. On occasion, tests will vary by something as small
Florent Xicluna73588542010-03-18 19:51:47 +0000130 as what type of input is used. Minimize code duplication by subclassing a
131 basic test class with a class that specifies the input::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000132
133 class TestFuncAcceptsSequences(unittest.TestCase):
134
135 func = mySuperWhammyFunction
136
137 def test_func(self):
138 self.func(self.arg)
139
140 class AcceptLists(TestFuncAcceptsSequences):
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000141 arg = [1, 2, 3]
Georg Brandl8ec7f652007-08-15 14:28:01 +0000142
143 class AcceptStrings(TestFuncAcceptsSequences):
144 arg = 'abc'
145
146 class AcceptTuples(TestFuncAcceptsSequences):
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000147 arg = (1, 2, 3)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000148
149
150.. seealso::
151
152 Test Driven Development
153 A book by Kent Beck on writing tests before code.
154
155
156.. _regrtest:
157
Éric Araujoa8132ec2010-12-16 03:53:53 +0000158Running tests using the command-line interface
159----------------------------------------------
Georg Brandl8ec7f652007-08-15 14:28:01 +0000160
Éric Araujoa8132ec2010-12-16 03:53:53 +0000161The :mod:`test.regrtest` module can be run as a script to drive Python's regression
162test suite, thanks to the :option:`-m` option: :program:`python -m test.regrtest`.
163Running the script by itself automatically starts running all regression
Georg Brandl8ec7f652007-08-15 14:28:01 +0000164tests in the :mod:`test` package. It does this by finding all modules in the
165package whose name starts with ``test_``, importing them, and executing the
Florent Xicluna73588542010-03-18 19:51:47 +0000166function :func:`test_main` if present. The names of tests to execute may also
167be passed to the script. Specifying a single regression test (:program:`python
Éric Araujoa8132ec2010-12-16 03:53:53 +0000168-m test.regrtest test_spam`) will minimize output and only print whether
169the test passed or failed and thus minimize output.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000170
171Running :mod:`test.regrtest` directly allows what resources are available for
R David Murray142ab322012-04-11 20:38:45 -0400172tests to use to be set. You do this by using the ``-u`` command-line
173option. Specifying ``all`` as the value for the ``-u`` option enables all
Berker Peksagb6886502016-04-27 08:58:32 +0300174possible resources: :program:`python -m test.regrtest -uall`.
R David Murray142ab322012-04-11 20:38:45 -0400175If all but one resource is desired (a more common case), a
Georg Brandl8ec7f652007-08-15 14:28:01 +0000176comma-separated list of resources that are not desired may be listed after
Éric Araujoa8132ec2010-12-16 03:53:53 +0000177``all``. The command :program:`python -m test.regrtest -uall,-audio,-largefile`
178will run :mod:`test.regrtest` with all resources except the ``audio`` and
179``largefile`` resources. For a list of all resources and more command-line
180options, run :program:`python -m test.regrtest -h`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000181
182Some other ways to execute the regression tests depend on what platform the
Éric Araujoa8132ec2010-12-16 03:53:53 +0000183tests are being executed on. On Unix, you can run :program:`make test` at the
184top-level directory where Python was built. On Windows, executing
185:program:`rt.bat` from your :file:`PCBuild` directory will run all regression
186tests.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000187
188
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300189:mod:`test.support` --- Utility functions for tests
190===================================================
Georg Brandl8ec7f652007-08-15 14:28:01 +0000191
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300192.. module:: test.support
Georg Brandl8ec7f652007-08-15 14:28:01 +0000193 :synopsis: Support for Python regression tests.
194
Brett Cannone76e4d72008-05-20 22:08:20 +0000195.. note::
196
197 The :mod:`test.test_support` module has been renamed to :mod:`test.support`
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300198 in Python 3.x and 2.7.13. The name ``test.test_support`` has been retained
199 as an alias in 2.7.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000200
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300201The :mod:`test.support` module provides support for Python's regression
Georg Brandl8ec7f652007-08-15 14:28:01 +0000202tests.
203
204This module defines the following exceptions:
205
206
207.. exception:: TestFailed
208
209 Exception to be raised when a test fails. This is deprecated in favor of
210 :mod:`unittest`\ -based tests and :class:`unittest.TestCase`'s assertion
211 methods.
212
213
Georg Brandl8ec7f652007-08-15 14:28:01 +0000214.. exception:: ResourceDenied
215
Florent Xicluna73588542010-03-18 19:51:47 +0000216 Subclass of :exc:`unittest.SkipTest`. Raised when a resource (such as a
217 network connection) is not available. Raised by the :func:`requires`
218 function.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000219
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300220The :mod:`test.support` module defines the following constants:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000221
222
223.. data:: verbose
224
225 :const:`True` when verbose output is enabled. Should be checked when more
226 detailed information is desired about a running test. *verbose* is set by
227 :mod:`test.regrtest`.
228
229
230.. data:: have_unicode
231
232 :const:`True` when Unicode support is available.
233
234
235.. data:: is_jython
236
237 :const:`True` if the running interpreter is Jython.
238
239
240.. data:: TESTFN
241
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000242 Set to a name that is safe to use as the name of a temporary file. Any
243 temporary file that is created should be closed and unlinked (removed).
Georg Brandl8ec7f652007-08-15 14:28:01 +0000244
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300245The :mod:`test.support` module defines the following functions:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000246
247
248.. function:: forget(module_name)
249
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000250 Remove the module named *module_name* from ``sys.modules`` and delete any
Georg Brandl8ec7f652007-08-15 14:28:01 +0000251 byte-compiled files of the module.
252
253
254.. function:: is_resource_enabled(resource)
255
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000256 Return :const:`True` if *resource* is enabled and available. The list of
Georg Brandl8ec7f652007-08-15 14:28:01 +0000257 available resources is only set when :mod:`test.regrtest` is executing the
258 tests.
259
260
261.. function:: requires(resource[, msg])
262
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000263 Raise :exc:`ResourceDenied` if *resource* is not available. *msg* is the
Florent Xicluna73588542010-03-18 19:51:47 +0000264 argument to :exc:`ResourceDenied` if it is raised. Always returns
265 :const:`True` if called by a function whose ``__name__`` is ``'__main__'``.
266 Used when tests are executed by :mod:`test.regrtest`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000267
268
269.. function:: findfile(filename)
270
Florent Xicluna73588542010-03-18 19:51:47 +0000271 Return the path to the file named *filename*. If no match is found
272 *filename* is returned. This does not equal a failure since it could be the
273 path to the file.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000274
275
276.. function:: run_unittest(*classes)
277
278 Execute :class:`unittest.TestCase` subclasses passed to the function. The
Florent Xicluna73588542010-03-18 19:51:47 +0000279 function scans the classes for methods starting with the prefix ``test_``
280 and executes the tests individually.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000281
282 It is also legal to pass strings as parameters; these should be keys in
283 ``sys.modules``. Each associated module will be scanned by
284 ``unittest.TestLoader.loadTestsFromModule()``. This is usually seen in the
285 following :func:`test_main` function::
286
287 def test_main():
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300288 support.run_unittest(__name__)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000289
290 This will run all tests defined in the named module.
291
Georg Brandl8ec7f652007-08-15 14:28:01 +0000292
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000293.. function:: check_warnings(*filters, quiet=True)
Georg Brandld558f672007-08-24 18:27:43 +0000294
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000295 A convenience wrapper for :func:`warnings.catch_warnings()` that makes it
296 easier to test that a warning was correctly raised. It is approximately
297 equivalent to calling ``warnings.catch_warnings(record=True)`` with
298 :meth:`warnings.simplefilter` set to ``always`` and with the option to
299 automatically validate the results that are recorded.
Nick Coghland2e09382008-09-11 12:11:06 +0000300
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000301 ``check_warnings`` accepts 2-tuples of the form ``("message regexp",
302 WarningCategory)`` as positional arguments. If one or more *filters* are
303 provided, or if the optional keyword argument *quiet* is :const:`False`,
304 it checks to make sure the warnings are as expected: each specified filter
305 must match at least one of the warnings raised by the enclosed code or the
306 test fails, and if any warnings are raised that do not match any of the
307 specified filters the test fails. To disable the first of these checks,
308 set *quiet* to :const:`True`.
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000309
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000310 If no arguments are specified, it defaults to::
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000311
Florent Xicluna73588542010-03-18 19:51:47 +0000312 check_warnings(("", Warning), quiet=True)
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000313
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000314 In this case all warnings are caught and no errors are raised.
Nick Coghland2e09382008-09-11 12:11:06 +0000315
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000316 On entry to the context manager, a :class:`WarningRecorder` instance is
317 returned. The underlying warnings list from
318 :func:`~warnings.catch_warnings` is available via the recorder object's
319 :attr:`warnings` attribute. As a convenience, the attributes of the object
320 representing the most recent warning can also be accessed directly through
321 the recorder object (see example below). If no warning has been raised,
322 then any of the attributes that would otherwise be expected on an object
323 representing a warning will return :const:`None`.
Georg Brandld558f672007-08-24 18:27:43 +0000324
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000325 The recorder object also has a :meth:`reset` method, which clears the
326 warnings list.
Georg Brandld558f672007-08-24 18:27:43 +0000327
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000328 The context manager is designed to be used like this::
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000329
330 with check_warnings(("assertion is always true", SyntaxWarning),
331 ("", UserWarning)):
332 exec('assert(False, "Hey!")')
333 warnings.warn(UserWarning("Hide me!"))
334
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000335 In this case if either warning was not raised, or some other warning was
336 raised, :func:`check_warnings` would raise an error.
337
338 When a test needs to look more deeply into the warnings, rather than
339 just checking whether or not they occurred, code like this can be used::
340
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000341 with check_warnings(quiet=True) as w:
Georg Brandld558f672007-08-24 18:27:43 +0000342 warnings.warn("foo")
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000343 assert str(w.args[0]) == "foo"
Nick Coghlan38469e22008-07-13 12:23:47 +0000344 warnings.warn("bar")
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000345 assert str(w.args[0]) == "bar"
346 assert str(w.warnings[0].args[0]) == "foo"
347 assert str(w.warnings[1].args[0]) == "bar"
Nick Coghland2e09382008-09-11 12:11:06 +0000348 w.reset()
349 assert len(w.warnings) == 0
Georg Brandld558f672007-08-24 18:27:43 +0000350
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000351 Here all warnings will be caught, and the test code tests the captured
352 warnings directly.
353
Georg Brandld558f672007-08-24 18:27:43 +0000354 .. versionadded:: 2.6
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000355 .. versionchanged:: 2.7
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000356 New optional arguments *filters* and *quiet*.
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000357
358
359.. function:: check_py3k_warnings(*filters, quiet=False)
360
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000361 Similar to :func:`check_warnings`, but for Python 3 compatibility warnings.
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000362 If ``sys.py3kwarning == 1``, it checks if the warning is effectively raised.
R. David Murray6c9fc4c2010-04-01 01:28:39 +0000363 If ``sys.py3kwarning == 0``, it checks that no warning is raised. It
364 accepts 2-tuples of the form ``("message regexp", WarningCategory)`` as
365 positional arguments. When the optional keyword argument *quiet* is
366 :const:`True`, it does not fail if a filter catches nothing. Without
367 arguments, it defaults to::
Florent Xiclunafc8a1ed2010-03-07 19:14:12 +0000368
369 check_py3k_warnings(("", DeprecationWarning), quiet=False)
370
371 .. versionadded:: 2.7
Georg Brandld558f672007-08-24 18:27:43 +0000372
373
374.. function:: captured_stdout()
375
Senthil Kumaran71a63242010-05-18 03:20:43 +0000376 This is a context manager that runs the :keyword:`with` statement body using
Georg Brandld558f672007-08-24 18:27:43 +0000377 a :class:`StringIO.StringIO` object as sys.stdout. That object can be
Andrew M. Kuchlingf15ff462008-01-15 01:29:44 +0000378 retrieved using the ``as`` clause of the :keyword:`with` statement.
Georg Brandld558f672007-08-24 18:27:43 +0000379
380 Example use::
381
382 with captured_stdout() as s:
383 print "hello"
Sandro Tosi466a5f22012-04-24 18:38:59 +0200384 assert s.getvalue() == "hello\n"
Georg Brandld558f672007-08-24 18:27:43 +0000385
386 .. versionadded:: 2.6
387
388
Nick Coghlancd2e7042009-04-11 13:31:31 +0000389.. function:: import_module(name, deprecated=False)
390
391 This function imports and returns the named module. Unlike a normal
392 import, this function raises :exc:`unittest.SkipTest` if the module
393 cannot be imported.
394
395 Module and package deprecation messages are suppressed during this import
396 if *deprecated* is :const:`True`.
397
398 .. versionadded:: 2.7
399
400
Nick Coghlan5533ff62009-04-22 15:26:04 +0000401.. function:: import_fresh_module(name, fresh=(), blocked=(), deprecated=False)
Nick Coghlancd2e7042009-04-11 13:31:31 +0000402
Nick Coghlan5533ff62009-04-22 15:26:04 +0000403 This function imports and returns a fresh copy of the named Python module
404 by removing the named module from ``sys.modules`` before doing the import.
405 Note that unlike :func:`reload`, the original module is not affected by
406 this operation.
407
408 *fresh* is an iterable of additional module names that are also removed
409 from the ``sys.modules`` cache before doing the import.
410
411 *blocked* is an iterable of module names that are replaced with :const:`0`
412 in the module cache during the import to ensure that attempts to import
413 them raise :exc:`ImportError`.
414
415 The named module and any modules named in the *fresh* and *blocked*
416 parameters are saved before starting the import and then reinserted into
417 ``sys.modules`` when the fresh import is complete.
Nick Coghlancd2e7042009-04-11 13:31:31 +0000418
419 Module and package deprecation messages are suppressed during this import
420 if *deprecated* is :const:`True`.
421
Berker Peksagb031adc2016-01-25 08:24:57 +0200422 This function will raise :exc:`unittest.SkipTest` if the named module
Nick Coghlan5533ff62009-04-22 15:26:04 +0000423 cannot be imported.
424
425 Example use::
426
427 # Get copies of the warnings module for testing without
428 # affecting the version being used by the rest of the test suite
429 # One copy uses the C implementation, the other is forced to use
430 # the pure Python fallback implementation
431 py_warnings = import_fresh_module('warnings', blocked=['_warnings'])
432 c_warnings = import_fresh_module('warnings', fresh=['_warnings'])
433
Nick Coghlancd2e7042009-04-11 13:31:31 +0000434 .. versionadded:: 2.7
435
436
Serhiy Storchakaa694e092017-04-30 11:36:58 +0300437The :mod:`test.support` module defines the following classes:
Georg Brandl8ec7f652007-08-15 14:28:01 +0000438
439.. class:: TransientResource(exc[, **kwargs])
440
441 Instances are a context manager that raises :exc:`ResourceDenied` if the
442 specified exception type is raised. Any keyword arguments are treated as
443 attribute/value pairs to be compared against any exception raised within the
444 :keyword:`with` statement. Only if all pairs match properly against
445 attributes on the exception is :exc:`ResourceDenied` raised.
446
447 .. versionadded:: 2.6
Georg Brandl8ec7f652007-08-15 14:28:01 +0000448.. class:: EnvironmentVarGuard()
449
Florent Xicluna73588542010-03-18 19:51:47 +0000450 Class used to temporarily set or unset environment variables. Instances can
451 be used as a context manager and have a complete dictionary interface for
452 querying/modifying the underlying ``os.environ``. After exit from the
453 context manager all changes to environment variables done through this
454 instance will be rolled back.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000455
456 .. versionadded:: 2.6
Walter Dörwald6733bed2009-05-01 17:35:37 +0000457 .. versionchanged:: 2.7
458 Added dictionary interface.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000459
460
461.. method:: EnvironmentVarGuard.set(envvar, value)
462
Florent Xicluna73588542010-03-18 19:51:47 +0000463 Temporarily set the environment variable ``envvar`` to the value of
464 ``value``.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000465
466
467.. method:: EnvironmentVarGuard.unset(envvar)
468
469 Temporarily unset the environment variable ``envvar``.
Nick Coghlan38469e22008-07-13 12:23:47 +0000470
Walter Dörwald6733bed2009-05-01 17:35:37 +0000471
Nick Coghland2e09382008-09-11 12:11:06 +0000472.. class:: WarningsRecorder()
473
474 Class used to record warnings for unit tests. See documentation of
475 :func:`check_warnings` above for more details.
476
477 .. versionadded:: 2.6