Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 | 1 |
2 :mod:`unittest` --- Unit testing framework | 2 :mod:`unittest` --- Unit testing framework |
3 ========================================== | 3 ========================================== |
4 | 4 |
5 .. module:: unittest | 5 .. module:: unittest |
6 :synopsis: Unit testing framework for Python. | 6 :synopsis: Unit testing framework for Python. |
7 .. moduleauthor:: Steve Purcell <stephen_purcell@yahoo.com> | 7 .. moduleauthor:: Steve Purcell <stephen_purcell@yahoo.com> |
8 .. sectionauthor:: Steve Purcell <stephen_purcell@yahoo.com> | 8 .. sectionauthor:: Steve Purcell <stephen_purcell@yahoo.com> |
9 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> | 9 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> |
10 .. sectionauthor:: Raymond Hettinger <python@rcn.com> | 10 .. sectionauthor:: Raymond Hettinger <python@rcn.com> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 The simplest :class:`TestCase` subclass will simply override the | 202 The simplest :class:`TestCase` subclass will simply override the |
203 :meth:`~TestCase.runTest` method in order to perform specific testing code:: | 203 :meth:`~TestCase.runTest` method in order to perform specific testing code:: |
204 | 204 |
205 import unittest | 205 import unittest |
206 | 206 |
207 class DefaultWidgetSizeTestCase(unittest.TestCase): | 207 class DefaultWidgetSizeTestCase(unittest.TestCase): |
208 def runTest(self): | 208 def runTest(self): |
209 widget = Widget('The widget') | 209 widget = Widget('The widget') |
210 self.assertEqual(widget.size(), (50, 50), 'incorrect default size') | 210 self.assertEqual(widget.size(), (50, 50), 'incorrect default size') |
211 | 211 |
212 Note that in order to test something, we use the one of the :meth:`assert\*` or | 212 Note that in order to test something, we use the one of the :meth:`assert\*` |
213 :meth:`fail\*` methods provided by the :class:`TestCase` base class. If the | 213 methods provided by the :class:`TestCase` base class. If the |
214 test fails, an exception will be raised, and :mod:`unittest` will identify the | 214 test fails, an exception will be raised, and :mod:`unittest` will identify the |
215 test case as a :dfn:`failure`. Any other exceptions will be treated as | 215 test case as a :dfn:`failure`. Any other exceptions will be treated as |
216 :dfn:`errors`. This helps you identify where the problem is: :dfn:`failures` are | 216 :dfn:`errors`. This helps you identify where the problem is: :dfn:`failures` are |
217 caused by incorrect results - a 5 where you expected a 6. :dfn:`Errors` are | 217 caused by incorrect results - a 5 where you expected a 6. :dfn:`Errors` are |
218 caused by incorrect code - e.g., a :exc:`TypeError` caused by an incorrect | 218 caused by incorrect code - e.g., a :exc:`TypeError` caused by an incorrect |
219 function call. | 219 function call. |
220 | 220 |
221 The way to run a test case will be described later. For now, note that to | 221 The way to run a test case will be described later. For now, note that to |
222 construct an instance of such a test case, we call its constructor without | 222 construct an instance of such a test case, we call its constructor without |
223 arguments:: | 223 arguments:: |
224 | 224 |
225 testCase = DefaultWidgetSizeTestCase() | 225 testCase = DefaultWidgetSizeTestCase() |
226 | 226 |
227 Now, such test cases can be numerous, and their set-up can be repetitive. In | 227 Now, such test cases can be numerous, and their set-up can be repetitive. In |
228 the above case, constructing a :class:`Widget` in each of 100 Widget test case | 228 the above case, constructing a :class:`Widget` in each of 100 Widget test case |
229 subclasses would mean unsightly duplication. | 229 subclasses would mean unsightly duplication. |
230 | 230 |
231 Luckily, we can factor out such set-up code by implementing a method called | 231 Luckily, we can factor out such set-up code by implementing a method called |
232 :meth:`~TestCase.setUp`, which the testing framework will automatically call for | 232 :meth:`~TestCase.setUp`, which the testing framework will automatically call for |
233 us when we run the test:: | 233 us when we run the test:: |
234 | 234 |
235 import unittest | 235 import unittest |
236 | 236 |
237 class SimpleWidgetTestCase(unittest.TestCase): | 237 class SimpleWidgetTestCase(unittest.TestCase): |
238 def setUp(self): | 238 def setUp(self): |
239 self.widget = Widget('The widget') | 239 self.widget = Widget('The widget') |
240 | 240 |
241 class DefaultWidgetSizeTestCase(SimpleWidgetTestCase): | 241 class DefaultWidgetSizeTestCase(SimpleWidgetTestCase): |
242 def runTest(self): | 242 def runTest(self): |
243 self.failUnless(self.widget.size() == (50,50), | 243 self.assertTrue(self.widget.size() == (50,50), |
244 'incorrect default size') | 244 'incorrect default size') |
245 | 245 |
246 class WidgetResizeTestCase(SimpleWidgetTestCase): | 246 class WidgetResizeTestCase(SimpleWidgetTestCase): |
247 def runTest(self): | 247 def runTest(self): |
248 self.widget.resize(100,150) | 248 self.widget.resize(100,150) |
249 self.failUnless(self.widget.size() == (100,150), | 249 self.assertTrue(self.widget.size() == (100,150), |
250 'wrong size after resize') | 250 'wrong size after resize') |
251 | 251 |
252 If the :meth:`~TestCase.setUp` method raises an exception while the test is | 252 If the :meth:`~TestCase.setUp` method raises an exception while the test is |
253 running, the framework will consider the test to have suffered an error, and the | 253 running, the framework will consider the test to have suffered an error, and the |
254 :meth:`~TestCase.runTest` method will not be executed. | 254 :meth:`~TestCase.runTest` method will not be executed. |
255 | 255 |
256 Similarly, we can provide a :meth:`~TestCase.tearDown` method that tidies up | 256 Similarly, we can provide a :meth:`~TestCase.tearDown` method that tidies up |
257 after the :meth:`~TestCase.runTest` method has been run:: | 257 after the :meth:`~TestCase.runTest` method has been run:: |
258 | 258 |
259 import unittest | 259 import unittest |
(...skipping 21 matching lines...) Expand all Loading... | |
281 | 281 |
282 class WidgetTestCase(unittest.TestCase): | 282 class WidgetTestCase(unittest.TestCase): |
283 def setUp(self): | 283 def setUp(self): |
284 self.widget = Widget('The widget') | 284 self.widget = Widget('The widget') |
285 | 285 |
286 def tearDown(self): | 286 def tearDown(self): |
287 self.widget.dispose() | 287 self.widget.dispose() |
288 self.widget = None | 288 self.widget = None |
289 | 289 |
290 def testDefaultSize(self): | 290 def testDefaultSize(self): |
291 self.failUnless(self.widget.size() == (50,50), | 291 self.assertTrue(self.widget.size() == (50,50), |
292 'incorrect default size') | 292 'incorrect default size') |
293 | 293 |
294 def testResize(self): | 294 def testResize(self): |
295 self.widget.resize(100,150) | 295 self.widget.resize(100,150) |
296 self.failUnless(self.widget.size() == (100,150), | 296 self.assertTrue(self.widget.size() == (100,150), |
297 'wrong size after resize') | 297 'wrong size after resize') |
298 | 298 |
299 Here we have not provided a :meth:`~TestCase.runTest` method, but have instead | 299 Here we have not provided a :meth:`~TestCase.runTest` method, but have instead |
300 provided two different test methods. Class instances will now each run one of | 300 provided two different test methods. Class instances will now each run one of |
301 the :meth:`test\*` methods, with ``self.widget`` created and destroyed | 301 the :meth:`test\*` methods, with ``self.widget`` created and destroyed |
302 separately for each instance. When creating an instance we must specify the | 302 separately for each instance. When creating an instance we must specify the |
303 test method it is to run. We do this by passing the method name in the | 303 test method it is to run. We do this by passing the method name in the |
304 constructor:: | 304 constructor:: |
305 | 305 |
306 defaultSizeTestCase = WidgetTestCase('testDefaultSize') | 306 defaultSizeTestCase = WidgetTestCase('testDefaultSize') |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 .. method:: debug() | 599 .. method:: debug() |
600 | 600 |
601 Run the test without collecting the result. This allows exceptions raised | 601 Run the test without collecting the result. This allows exceptions raised |
602 by the test to be propagated to the caller, and can be used to support | 602 by the test to be propagated to the caller, and can be used to support |
603 running tests under a debugger. | 603 running tests under a debugger. |
604 | 604 |
605 The test code can use any of the following methods to check for and report | 605 The test code can use any of the following methods to check for and report |
606 failures. | 606 failures. |
607 | 607 |
608 | 608 |
609 .. method:: assert_(expr[, msg]) | 609 .. method:: assertTrue(expr[, msg]) |
610 assert_(expr[, msg]) | |
610 failUnless(expr[, msg]) | 611 failUnless(expr[, msg]) |
611 assertTrue(expr[, msg]) | |
GvR
2009/03/31 15:01:06
Make assertTrue the first/preferred/recommended sp
gregory.p.smith
2009/03/31 16:37:02
Done.
| |
612 | 612 |
613 Signal a test failure if *expr* is false; the explanation for the error | 613 Signal a test failure if *expr* is false; the explanation for the error |
614 will be *msg* if given, otherwise it will be :const:`None`. | 614 will be *msg* if given, otherwise it will be :const:`None`. |
615 | 615 |
616 | 616 |
617 .. method:: assertEqual(first, second[, msg]) | 617 .. method:: assertEqual(first, second[, msg]) |
618 assertEquals(first, second[, msg]) | |
619 failUnlessEqual(first, second[, msg]) | 618 failUnlessEqual(first, second[, msg]) |
620 | 619 |
621 Test that *first* and *second* are equal. If the values do not compare | 620 Test that *first* and *second* are equal. If the values do not compare |
622 equal, the test will fail with the explanation given by *msg*, or | 621 equal, the test will fail with the explanation given by *msg*, or |
623 :const:`None`. Note that using :meth:`failUnlessEqual` improves upon | 622 :const:`None`. Note that using :meth:`assertEqual` improves upon |
GvR
2009/03/31 15:01:06
failUnlessEqal -> assertEqual
gregory.p.smith
2009/03/31 16:37:02
Done.
| |
624 doing the comparison as the first parameter to :meth:`failUnless`: the | 623 doing the comparison as the first parameter to :meth:`assertTrue`: the |
GvR
2009/03/31 15:01:06
failUnless -> assertTrue
(This kind of change may
gregory.p.smith
2009/03/31 16:37:02
Done.
| |
625 default value for *msg* include representations of both *first* and | 624 default value for *msg* include representations of both *first* and |
626 *second*. | 625 *second*. |
627 | 626 |
628 In addition, if *first* and *second* are the exact same type and one of | 627 In addition, if *first* and *second* are the exact same type and one of |
629 list, tuple, dict, set, or frozenset or any type that a subclass | 628 list, tuple, dict, set, or frozenset or any type that a subclass |
630 registers :meth:`addTypeEqualityFunc` the type specific equality function | 629 registers :meth:`addTypeEqualityFunc` the type specific equality function |
631 will be called in order to generate a more useful default error message. | 630 will be called in order to generate a more useful default error message. |
632 | 631 |
633 .. versionchanged:: 2.7 | 632 .. versionchanged:: 2.7 |
634 Added the automatic calling of type specific equality function. | 633 Added the automatic calling of type specific equality function. |
635 | 634 |
636 | 635 |
637 .. method:: assertNotEqual(first, second[, msg]) | 636 .. method:: assertNotEqual(first, second[, msg]) |
638 failIfEqual(first, second[, msg]) | 637 failIfEqual(first, second[, msg]) |
639 | 638 |
640 Test that *first* and *second* are not equal. If the values do compare | 639 Test that *first* and *second* are not equal. If the values do compare |
641 equal, the test will fail with the explanation given by *msg*, or | 640 equal, the test will fail with the explanation given by *msg*, or |
642 :const:`None`. Note that using :meth:`failIfEqual` improves upon doing | 641 :const:`None`. Note that using :meth:`assertNotEqual` improves upon doing |
643 the comparison as the first parameter to :meth:`failUnless` is that the | 642 the comparison as the first parameter to :meth:`assertTrue` is that the |
644 default value for *msg* can be computed to include representations of both | 643 default value for *msg* can be computed to include representations of both |
645 *first* and *second*. | 644 *first* and *second*. |
646 | 645 |
647 | 646 |
648 .. method:: assertAlmostEqual(first, second[, places[, msg]]) | 647 .. method:: assertAlmostEqual(first, second[, places[, msg]]) |
649 failUnlessAlmostEqual(first, second[, places[, msg]]) | 648 failUnlessAlmostEqual(first, second[, places[, msg]]) |
650 | 649 |
651 Test that *first* and *second* are approximately equal by computing the | 650 Test that *first* and *second* are approximately equal by computing the |
652 difference, rounding to the given number of decimal *places* (default 7), | 651 difference, rounding to the given number of decimal *places* (default 7), |
653 and comparing to zero. | 652 and comparing to zero. |
(...skipping 25 matching lines...) Expand all Loading... | |
679 Test that *first* is respectively >, >=, < or <= than *second* depending | 678 Test that *first* is respectively >, >=, < or <= than *second* depending |
680 on the method name. If not, the test will fail with the nice explanation | 679 on the method name. If not, the test will fail with the nice explanation |
681 or with the explanation given by *msg*:: | 680 or with the explanation given by *msg*:: |
682 | 681 |
683 >>> self.assertGreaterEqual(3, 4) | 682 >>> self.assertGreaterEqual(3, 4) |
684 AssertionError: "3" unexpectedly not greater than or equal to "4" | 683 AssertionError: "3" unexpectedly not greater than or equal to "4" |
685 | 684 |
686 .. versionadded:: 2.7 | 685 .. versionadded:: 2.7 |
687 | 686 |
688 | 687 |
689 .. method:: assertMultiLineEquals(self, first, second, msg=None) | 688 .. method:: assertMultiLineEqual(self, first, second, msg=None) |
690 | 689 |
691 Test that the multiline string *first* is equal to the string *second*. | 690 Test that the multiline string *first* is equal to the string *second*. |
692 When not equal a diff of the two strings highlighting the differences | 691 When not equal a diff of the two strings highlighting the differences |
693 will be included in the error message. | 692 will be included in the error message. |
694 | 693 |
695 If specified *msg* will be used as the error message on failure. | 694 If specified *msg* will be used as the error message on failure. |
696 | 695 |
697 .. versionadded:: 2.7 | 696 .. versionadded:: 2.7 |
698 | 697 |
699 | 698 |
(...skipping 22 matching lines...) Expand all Loading... | |
722 | 721 |
723 Test that sequence *expected* contains the same elements as *actual*. | 722 Test that sequence *expected* contains the same elements as *actual*. |
724 When they don't an error message listing the differences between the | 723 When they don't an error message listing the differences between the |
725 sequences will be generated. | 724 sequences will be generated. |
726 | 725 |
727 If specified *msg* will be used as the error message on failure. | 726 If specified *msg* will be used as the error message on failure. |
728 | 727 |
729 .. versionadded:: 2.7 | 728 .. versionadded:: 2.7 |
730 | 729 |
731 | 730 |
732 .. method:: assertSetEquals(set1, set2, msg=None) | 731 .. method:: assertSetEqual(set1, set2, msg=None) |
733 | 732 |
734 Tests that two sets are equal. If not, an error message is constructed | 733 Tests that two sets are equal. If not, an error message is constructed |
735 that lists the differences between the sets. | 734 that lists the differences between the sets. |
736 | 735 |
737 Fails if either of *set1* or *set2* does not have a :meth:`set.difference` | 736 Fails if either of *set1* or *set2* does not have a :meth:`set.difference` |
738 method. | 737 method. |
739 | 738 |
740 If specified *msg* will be used as the error message on failure. | 739 If specified *msg* will be used as the error message on failure. |
741 | 740 |
742 .. versionadded:: 2.7 | 741 .. versionadded:: 2.7 |
743 | 742 |
744 | 743 |
745 .. method:: assertDictEquals(expected, actual, msg=None) | 744 .. method:: assertDictEqual(expected, actual, msg=None) |
746 | 745 |
747 Test that two dictionaries are equal. If not, an error message is | 746 Test that two dictionaries are equal. If not, an error message is |
748 constructed that shows the differences in the dictionaries. | 747 constructed that shows the differences in the dictionaries. |
749 | 748 |
750 If specified *msg* will be used as the error message on failure. | 749 If specified *msg* will be used as the error message on failure. |
751 | 750 |
752 .. versionadded:: 2.7 | 751 .. versionadded:: 2.7 |
753 | 752 |
754 | 753 |
755 .. method:: assertDictContainsSubset(expected, actual, msg=None) | 754 .. method:: assertDictContainsSubset(expected, actual, msg=None) |
756 | 755 |
757 Tests whether the key value pairs in dictionary *actual* are a | 756 Tests whether the key value pairs in dictionary *actual* are a |
758 superset of those in *expected*. If not, an error message listing | 757 superset of those in *expected*. If not, an error message listing |
759 the missing keys and mismatched values is generated. | 758 the missing keys and mismatched values is generated. |
760 | 759 |
761 If specified *msg* will be used as the error message on failure. | 760 If specified *msg* will be used as the error message on failure. |
762 | 761 |
763 .. versionadded:: 2.7 | 762 .. versionadded:: 2.7 |
764 | 763 |
765 | 764 |
766 .. method:: assertListEquals(list1, list2, msg=None) | 765 .. method:: assertListEqual(list1, list2, msg=None) |
767 assertTupleEquals(tuple1, tuple2, msg=None) | 766 assertTupleEqual(tuple1, tuple2, msg=None) |
768 | 767 |
769 Tests that two lists or tuples are equal. If not an error message is | 768 Tests that two lists or tuples are equal. If not an error message is |
770 constructed that shows only the differences between the two. An error | 769 constructed that shows only the differences between the two. An error |
771 is also raised if either of the parameters are of the wrong type. | 770 is also raised if either of the parameters are of the wrong type. |
772 | 771 |
773 If specified *msg* will be used as the error message on failure. | 772 If specified *msg* will be used as the error message on failure. |
774 | 773 |
775 .. versionadded:: 2.7 | 774 .. versionadded:: 2.7 |
776 | 775 |
777 | 776 |
778 .. method:: assertSequenceEquals(seq1, seq2, msg=None, seq_type=None) | 777 .. method:: assertSequenceEqual(seq1, seq2, msg=None, seq_type=None) |
779 | 778 |
780 Tests that two sequences are equal. If a *seq_type* is supplied, both | 779 Tests that two sequences are equal. If a *seq_type* is supplied, both |
781 *seq1* and *seq2* must be instances of *seq_type* or a failure will | 780 *seq1* and *seq2* must be instances of *seq_type* or a failure will |
782 be raised. If the sequences are different an error message is | 781 be raised. If the sequences are different an error message is |
783 constructed that shows the difference between the two. | 782 constructed that shows the difference between the two. |
784 | 783 |
785 If specified *msg* will be used as the error message on failure. | 784 If specified *msg* will be used as the error message on failure. |
786 | 785 |
787 This method is used to implement :meth:`assertListEquals` and | 786 This method is used to implement :meth:`assertListEqual` and |
788 :meth:`assertTupleEquals`. | 787 :meth:`assertTupleEqual`. |
789 | 788 |
790 .. versionadded:: 2.7 | 789 .. versionadded:: 2.7 |
791 | 790 |
792 | 791 |
793 .. method:: assertRaises(exception[, callable, ...]) | 792 .. method:: assertRaises(exception[, callable, ...]) |
794 failUnlessRaises(exception[, callable, ...]) | 793 failUnlessRaises(exception[, callable, ...]) |
795 | 794 |
796 Test that an exception is raised when *callable* is called with any | 795 Test that an exception is raised when *callable* is called with any |
797 positional or keyword arguments that are also passed to | 796 positional or keyword arguments that are also passed to |
798 :meth:`assertRaises`. The test passes if *exception* is raised, is an | 797 :meth:`assertRaises`. The test passes if *exception* is raised, is an |
(...skipping 13 matching lines...) Expand all Loading... | |
812 | 811 |
813 .. method:: assertRaisesRegexp(exception, regexp[, callable, ...]) | 812 .. method:: assertRaisesRegexp(exception, regexp[, callable, ...]) |
814 | 813 |
815 Like :meth:`assertRaises` but also tests that *regexp* matches | 814 Like :meth:`assertRaises` but also tests that *regexp* matches |
816 on the string representation of the raised exception. *regexp* may be | 815 on the string representation of the raised exception. *regexp* may be |
817 a regular expression object or a string containing a regular expression | 816 a regular expression object or a string containing a regular expression |
818 suitable for use by :func:`re.search`. Examples:: | 817 suitable for use by :func:`re.search`. Examples:: |
819 | 818 |
820 self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ$', | 819 self.assertRaisesRegexp(ValueError, 'invalid literal for.*XYZ$', |
821 int, 'XYZ') | 820 int, 'XYZ') |
822 | 821 |
823 or:: | 822 or:: |
824 | 823 |
825 with self.assertRaisesRegexp(ValueError, 'literal'): | 824 with self.assertRaisesRegexp(ValueError, 'literal'): |
826 int('XYZ') | 825 int('XYZ') |
827 | 826 |
828 .. versionadded:: 2.7 | 827 .. versionadded:: 2.7 |
829 | 828 |
830 | 829 |
831 .. method:: assertIsNone(expr[, msg]) | 830 .. method:: assertIsNone(expr[, msg]) |
832 | 831 |
833 This signals a test failure if *expr* is not None. | 832 This signals a test failure if *expr* is not None. |
834 | 833 |
835 .. versionadded:: 2.7 | 834 .. versionadded:: 2.7 |
836 | 835 |
837 | 836 |
838 .. method:: assertIsNotNone(expr[, msg]) | 837 .. method:: assertIsNotNone(expr[, msg]) |
839 | 838 |
840 The inverse of the :meth:`assertIsNone` method. | 839 The inverse of the :meth:`assertIsNone` method. |
841 This signals a test failure if *expr* is None. | 840 This signals a test failure if *expr* is None. |
842 | 841 |
843 .. versionadded:: 2.7 | 842 .. versionadded:: 2.7 |
844 | 843 |
845 | 844 |
846 .. method:: failIf(expr[, msg]) | 845 .. method:: assertFalse(expr[, msg]) |
847 assertFalse(expr[, msg]) | 846 failIf(expr[, msg]) |
848 | 847 |
849 The inverse of the :meth:`failUnless` method is the :meth:`failIf` method. | 848 The inverse of the :meth:`assertTrue` method is the :meth:`assertFalse` me thod. |
850 This signals a test failure if *expr* is true, with *msg* or :const:`None` | 849 This signals a test failure if *expr* is true, with *msg* or :const:`None` |
851 for the error message. | 850 for the error message. |
852 | 851 |
853 | 852 |
854 .. method:: fail([msg]) | 853 .. method:: fail([msg]) |
855 | 854 |
856 Signals a test failure unconditionally, with *msg* or :const:`None` for | 855 Signals a test failure unconditionally, with *msg* or :const:`None` for |
857 the error message. | 856 the error message. |
858 | 857 |
859 | 858 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 .. versionchanged:: 2.7 | 901 .. versionchanged:: 2.7 |
903 | 902 |
904 In earlier versions this only returned the first line of the test | 903 In earlier versions this only returned the first line of the test |
905 method's docstring, if available or the :const:`None`. That led to | 904 method's docstring, if available or the :const:`None`. That led to |
906 undesirable behavior of not printing the test name when someone was | 905 undesirable behavior of not printing the test name when someone was |
907 thoughtful enough to write a docstring. | 906 thoughtful enough to write a docstring. |
908 | 907 |
909 | 908 |
910 .. method:: addTypeEqualityFunc(typeobj, function) | 909 .. method:: addTypeEqualityFunc(typeobj, function) |
911 | 910 |
912 Registers a type specific :meth:`assertEquals` equality checking | 911 Registers a type specific :meth:`assertEqual` equality checking |
913 function to be called by :meth:`assertEquals` when both objects it has | 912 function to be called by :meth:`assertEqual` when both objects it has |
914 been asked to compare are exactly *typeobj* (not subclasses). | 913 been asked to compare are exactly *typeobj* (not subclasses). |
915 *function* must take two positional arguments and a third msg=None | 914 *function* must take two positional arguments and a third msg=None |
916 keyword argument just as :meth:`assertEquals` does. It must raise | 915 keyword argument just as :meth:`assertEqual` does. It must raise |
917 self.failureException when inequality between the first two | 916 self.failureException when inequality between the first two |
918 parameters is detected. | 917 parameters is detected. |
919 | 918 |
920 One good use of custom equality checking functions for a type | 919 One good use of custom equality checking functions for a type |
921 is to raise self.failureException with an error message useful | 920 is to raise self.failureException with an error message useful |
922 for debugging the by explaining the inequalities in detail. | 921 for debugging the by explaining the inequalities in detail. |
923 | 922 |
924 .. versionadded:: 2.7 | 923 .. versionadded:: 2.7 |
925 | 924 |
926 | 925 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1296 | 1295 |
1297 A command-line program that runs a set of tests; this is primarily for making | 1296 A command-line program that runs a set of tests; this is primarily for making |
1298 test modules conveniently executable. The simplest use for this function is to | 1297 test modules conveniently executable. The simplest use for this function is to |
1299 include the following line at the end of a test script:: | 1298 include the following line at the end of a test script:: |
1300 | 1299 |
1301 if __name__ == '__main__': | 1300 if __name__ == '__main__': |
1302 unittest.main() | 1301 unittest.main() |
1303 | 1302 |
1304 The *testRunner* argument can either be a test runner class or an already | 1303 The *testRunner* argument can either be a test runner class or an already |
1305 created instance of it. | 1304 created instance of it. |
LEFT | RIGHT |