@@ -510,7 +510,8 @@ that is broken and will fail, but shouldn't be counted as a failure on a
510
510
:class: `TestResult `.
511
511
512
512
Skipping a test is simply a matter of using the :func: `skip ` :term: `decorator `
513
- or one of its conditional variants.
513
+ or one of its conditional variants, calling :meth: `TestCase.skipTest ` within a
514
+ :meth: `~TestCase.setUp ` or test method, or raising :exc: `SkipTest ` directly.
514
515
515
516
Basic skipping looks like this::
516
517
@@ -531,16 +532,23 @@ Basic skipping looks like this::
531
532
# windows specific testing code
532
533
pass
533
534
535
+ def test_maybe_skipped(self):
536
+ if not external_resource_available():
537
+ self.skipTest("external resource not available")
538
+ # test code that depends on the external resource
539
+ pass
540
+
534
541
This is the output of running the example above in verbose mode::
535
542
536
543
test_format (__main__.MyTestCase) ... skipped 'not supported in this library version'
537
544
test_nothing (__main__.MyTestCase) ... skipped 'demonstrating skipping'
545
+ test_maybe_skipped (__main__.MyTestCase) ... skipped 'external resource not available'
538
546
test_windows_support (__main__.MyTestCase) ... skipped 'requires Windows'
539
547
540
548
----------------------------------------------------------------------
541
- Ran 3 tests in 0.005s
549
+ Ran 4 tests in 0.005s
542
550
543
- OK (skipped=3 )
551
+ OK (skipped=4 )
544
552
545
553
Classes can be skipped just like methods::
546
554
@@ -568,7 +576,7 @@ the test unless the passed object has a certain attribute::
568
576
return lambda func: func
569
577
return unittest.skip("{!r} doesn't have {!r}".format(obj, attr))
570
578
571
- The following decorators implement test skipping and expected failures:
579
+ The following decorators and exception implement test skipping and expected failures:
572
580
573
581
.. decorator :: skip(reason)
574
582
0 commit comments