Back to index

python3.2  3.2.2
Public Member Functions
unittest.test.test_skipping.Test_TestSkipping Class Reference

List of all members.

Public Member Functions

def test_skipping
def test_skipping_decorators
def test_skip_class
def test_expected_failure
def test_unexpected_success
def test_skip_doesnt_run_setup
def test_decorated_skip

Detailed Description

Definition at line 6 of file test_skipping.py.


Member Function Documentation

Definition at line 118 of file test_skipping.py.

00118 
00119     def test_decorated_skip(self):
00120         def decorator(func):
00121             def inner(*a):
00122                 return func(*a)
00123             return inner
00124 
00125         class Foo(unittest.TestCase):
00126             @decorator
00127             @unittest.skip('testing')
00128             def test_1(self):
00129                 pass
00130 
00131         result = unittest.TestResult()
00132         test = Foo("test_1")
00133         suite = unittest.TestSuite([test])
00134         suite.run(result)
00135         self.assertEqual(result.skipped, [(test, "testing")])

Here is the call graph for this function:

Definition at line 69 of file test_skipping.py.

00069 
00070     def test_expected_failure(self):
00071         class Foo(unittest.TestCase):
00072             @unittest.expectedFailure
00073             def test_die(self):
00074                 self.fail("help me!")
00075         events = []
00076         result = LoggingResult(events)
00077         test = Foo("test_die")
00078         test.run(result)
00079         self.assertEqual(events,
00080                          ['startTest', 'addExpectedFailure', 'stopTest'])
00081         self.assertEqual(result.expectedFailures[0][0], test)
00082         self.assertTrue(result.wasSuccessful())

Here is the call graph for this function:

Definition at line 56 of file test_skipping.py.

00056 
00057     def test_skip_class(self):
00058         @unittest.skip("testing")
00059         class Foo(unittest.TestCase):
00060             def test_1(self):
00061                 record.append(1)
00062         record = []
00063         result = unittest.TestResult()
00064         test = Foo("test_1")
00065         suite = unittest.TestSuite([test])
00066         suite.run(result)
00067         self.assertEqual(result.skipped, [(test, "testing")])
00068         self.assertEqual(record, [])

Here is the call graph for this function:

Definition at line 98 of file test_skipping.py.

00098 
00099     def test_skip_doesnt_run_setup(self):
00100         class Foo(unittest.TestCase):
00101             wasSetUp = False
00102             wasTornDown = False
00103             def setUp(self):
00104                 Foo.wasSetUp = True
00105             def tornDown(self):
00106                 Foo.wasTornDown = True
00107             @unittest.skip('testing')
00108             def test_1(self):
00109                 pass
00110 
00111         result = unittest.TestResult()
00112         test = Foo("test_1")
00113         suite = unittest.TestSuite([test])
00114         suite.run(result)
00115         self.assertEqual(result.skipped, [(test, "testing")])
00116         self.assertFalse(Foo.wasSetUp)
00117         self.assertFalse(Foo.wasTornDown)

Here is the call graph for this function:

Definition at line 8 of file test_skipping.py.

00008 
00009     def test_skipping(self):
00010         class Foo(unittest.TestCase):
00011             def test_skip_me(self):
00012                 self.skipTest("skip")
00013         events = []
00014         result = LoggingResult(events)
00015         test = Foo("test_skip_me")
00016         test.run(result)
00017         self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])
00018         self.assertEqual(result.skipped, [(test, "skip")])
00019 
00020         # Try letting setUp skip the test now.
00021         class Foo(unittest.TestCase):
00022             def setUp(self):
00023                 self.skipTest("testing")
00024             def test_nothing(self): pass
00025         events = []
00026         result = LoggingResult(events)
00027         test = Foo("test_nothing")
00028         test.run(result)
00029         self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])
00030         self.assertEqual(result.skipped, [(test, "testing")])
00031         self.assertEqual(result.testsRun, 1)

Here is the call graph for this function:

Definition at line 32 of file test_skipping.py.

00032 
00033     def test_skipping_decorators(self):
00034         op_table = ((unittest.skipUnless, False, True),
00035                     (unittest.skipIf, True, False))
00036         for deco, do_skip, dont_skip in op_table:
00037             class Foo(unittest.TestCase):
00038                 @deco(do_skip, "testing")
00039                 def test_skip(self): pass
00040 
00041                 @deco(dont_skip, "testing")
00042                 def test_dont_skip(self): pass
00043             test_do_skip = Foo("test_skip")
00044             test_dont_skip = Foo("test_dont_skip")
00045             suite = unittest.TestSuite([test_do_skip, test_dont_skip])
00046             events = []
00047             result = LoggingResult(events)
00048             suite.run(result)
00049             self.assertEqual(len(result.skipped), 1)
00050             expected = ['startTest', 'addSkip', 'stopTest',
00051                         'startTest', 'addSuccess', 'stopTest']
00052             self.assertEqual(events, expected)
00053             self.assertEqual(result.testsRun, 2)
00054             self.assertEqual(result.skipped, [(test_do_skip, "testing")])
00055             self.assertTrue(result.wasSuccessful())

Here is the call graph for this function:

Definition at line 83 of file test_skipping.py.

00083 
00084     def test_unexpected_success(self):
00085         class Foo(unittest.TestCase):
00086             @unittest.expectedFailure
00087             def test_die(self):
00088                 pass
00089         events = []
00090         result = LoggingResult(events)
00091         test = Foo("test_die")
00092         test.run(result)
00093         self.assertEqual(events,
00094                          ['startTest', 'addUnexpectedSuccess', 'stopTest'])
00095         self.assertFalse(result.failures)
00096         self.assertEqual(result.unexpectedSuccesses, [test])
00097         self.assertTrue(result.wasSuccessful())


The documentation for this class was generated from the following file: