@@ -130,13 +130,13 @@ guidelines to be followed:
130130 self.func(self.arg)
131131
132132 class AcceptLists(TestFuncAcceptsSequences):
133- arg = [1,2, 3]
133+ arg = [1, 2, 3]
134134
135135 class AcceptStrings(TestFuncAcceptsSequences):
136136 arg = 'abc'
137137
138138 class AcceptTuples(TestFuncAcceptsSequences):
139- arg = (1,2, 3)
139+ arg = (1, 2, 3)
140140
141141
142142.. seealso ::
@@ -198,16 +198,9 @@ This module defines the following exceptions:
198198 methods.
199199
200200
201- .. exception :: TestSkipped
202-
203- Subclass of :exc: `TestFailed `. Raised when a test is skipped. This occurs when a
204- needed resource (such as a network connection) is not available at the time of
205- testing.
206-
207-
208201.. exception :: ResourceDenied
209202
210- Subclass of :exc: `TestSkipped `. Raised when a resource (such as a network
203+ Subclass of :exc: `unittest.SkipTest `. Raised when a resource (such as a network
211204 connection) is not available. Raised by the :func: `requires ` function.
212205
213206The :mod: `test.support ` module defines the following constants:
@@ -227,29 +220,29 @@ The :mod:`test.support` module defines the following constants:
227220
228221.. data :: TESTFN
229222
230- Set to the path that a temporary file may be created at . Any temporary that is
223+ Set to the name that a temporary file could use . Any temporary file that is
231224 created should be closed and unlinked (removed).
232225
233226The :mod: `test.support ` module defines the following functions:
234227
235228
236229.. function :: forget(module_name)
237230
238- Removes the module named *module_name * from ``sys.modules `` and deletes any
231+ Remove the module named *module_name * from ``sys.modules `` and deletes any
239232 byte-compiled files of the module.
240233
241234
242235.. function :: is_resource_enabled(resource)
243236
244- Returns :const: `True ` if *resource * is enabled and available. The list of
237+ Return :const: `True ` if *resource * is enabled and available. The list of
245238 available resources is only set when :mod: `test.regrtest ` is executing the
246239 tests.
247240
248241
249242.. function :: requires(resource, msg=None)
250243
251- Raises :exc: `ResourceDenied ` if *resource * is not available. *msg * is the
252- argument to :exc: `ResourceDenied ` if it is raised. Always returns true if called
244+ Raise :exc: `ResourceDenied ` if *resource * is not available. *msg * is the
245+ argument to :exc: `ResourceDenied ` if it is raised. Always returns True if called
253246 by a function whose ``__name__ `` is ``'__main__' ``. Used when tests are executed
254247 by :mod: `test.regrtest `.
255248
@@ -277,14 +270,24 @@ The :mod:`test.support` module defines the following functions:
277270 This will run all tests defined in the named module.
278271
279272
280- .. function :: check_warnings()
273+ .. function :: check_warnings(*filters, quiet=False )
281274
282275 A convenience wrapper for ``warnings.catch_warnings() `` that makes
283276 it easier to test that a warning was correctly raised with a single
284277 assertion. It is approximately equivalent to calling
285278 ``warnings.catch_warnings(record=True) ``.
286279
287- The main difference is that on entry to the context manager, a
280+ It accepts 2-tuples ``("message regexp", WarningCategory) `` as positional
281+ arguments. When the optional keyword argument ``quiet `` is True, it does
282+ not fail if a filter catches nothing. Without argument, it defaults to::
283+
284+ check_warnings(("", Warning), quiet=False)
285+
286+ The main difference is that it verifies the warnings raised. If some filter
287+ did not catch any warning, the test fails. If some warnings are not caught,
288+ the test fails, too. To disable these checks, use argument ``quiet=True ``.
289+
290+ Another significant difference is that on entry to the context manager, a
288291 :class: `WarningRecorder ` instance is returned instead of a simple list.
289292 The underlying warnings list is available via the recorder object's
290293 :attr: `warnings ` attribute, while the attributes of the last raised
@@ -294,19 +297,34 @@ The :mod:`test.support` module defines the following functions:
294297 A :meth: `reset ` method is also provided on the recorder object. This
295298 method simply clears the warning list.
296299
297- The context manager is used like this::
300+ The context manager may be used like this::
301+
302+ import warnings
303+
304+ with check_warnings():
305+ exec('assert(False, "Hey!")')
306+ warnings.warn(UserWarning("Hide me!"))
298307
299- with check_warnings() as w:
308+ with check_warnings(("assertion is always true", SyntaxWarning),
309+ ("", UserWarning)):
310+ exec('assert(False, "Hey!")')
311+ warnings.warn(UserWarning("Hide me!"))
312+
313+ with check_warnings(quiet=True) as w:
300314 warnings.simplefilter("always")
301315 warnings.warn("foo")
302- assert str(w.message ) == "foo"
316+ assert str(w.args[0] ) == "foo"
303317 warnings.warn("bar")
304- assert str(w.message ) == "bar"
305- assert str(w.warnings[0].message ) == "foo"
306- assert str(w.warnings[1].message ) == "bar"
318+ assert str(w.args[0] ) == "bar"
319+ assert str(w.warnings[0].args[0] ) == "foo"
320+ assert str(w.warnings[1].args[0] ) == "bar"
307321 w.reset()
308322 assert len(w.warnings) == 0
309323
324+ .. versionchanged :: 2.7
325+ The test fails when the context manager do not catch any warning.
326+ New optional attributes ``*filters `` and ``quiet ``.
327+
310328
311329.. function :: captured_stdout()
312330
0 commit comments