Best Python code snippet using autotest_python
test_loader.py
Source:test_loader.py
...460 if module_name in sys.modules:461 del sys.modules[module_name]462 ################################################################463 # Tests for TestLoader.loadTestsFromName()464 # Tests for TestLoader.loadTestsFromNames()465 ################################################################466 # "Similar to loadTestsFromName(), but takes a sequence of names rather467 # than a single name."468 #469 # What happens if that sequence of names is empty?470 def test_loadTestsFromNames__empty_name_list(self):471 loader = unittest2.TestLoader()472 suite = loader.loadTestsFromNames([])473 self.assertIsInstance(suite, loader.suiteClass)474 self.assertEqual(list(suite), [])475 # "Similar to loadTestsFromName(), but takes a sequence of names rather476 # than a single name."477 # ...478 # "The method optionally resolves name relative to the given module"479 #480 # What happens if that sequence of names is empty?481 #482 # XXX Should this raise a ValueError or just return an empty TestSuite?483 def test_loadTestsFromNames__relative_empty_name_list(self):484 loader = unittest2.TestLoader()485 suite = loader.loadTestsFromNames([], unittest2)486 self.assertIsInstance(suite, loader.suiteClass)487 self.assertEqual(list(suite), [])488 # "The specifier name is a ``dotted name'' that may resolve either to489 # a module, a test case class, a TestSuite instance, a test method490 # within a test case class, or a callable object which returns a491 # TestCase or TestSuite instance."492 #493 # Is ValueError raised in response to an empty name?494 def test_loadTestsFromNames__empty_name(self):495 loader = unittest2.TestLoader()496 try:497 loader.loadTestsFromNames([''])498 except ValueError as e:499 self.assertEqual(str(e), "Empty module name")500 else:501 self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")502 # "The specifier name is a ``dotted name'' that may resolve either to503 # a module, a test case class, a TestSuite instance, a test method504 # within a test case class, or a callable object which returns a505 # TestCase or TestSuite instance."506 #507 # What happens when presented with an impossible module name?508 def test_loadTestsFromNames__malformed_name(self):509 loader = unittest2.TestLoader()510 # XXX Should this raise ValueError or ImportError?511 try:512 loader.loadTestsFromNames(['abc () //'])513 except ValueError:514 pass515 except ImportError:516 pass517 else:518 self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")519 # "The specifier name is a ``dotted name'' that may resolve either to520 # a module, a test case class, a TestSuite instance, a test method521 # within a test case class, or a callable object which returns a522 # TestCase or TestSuite instance."523 #524 # What happens when no module can be found for the given name?525 def test_loadTestsFromNames__unknown_module_name(self):526 loader = unittest2.TestLoader()527 try:528 loader.loadTestsFromNames(['sdasfasfasdf'])529 except ImportError as e:530 self.assertEqual(str(e), "No module named sdasfasfasdf")531 else:532 self.fail("TestLoader.loadTestsFromNames failed to raise ImportError")533 # "The specifier name is a ``dotted name'' that may resolve either to534 # a module, a test case class, a TestSuite instance, a test method535 # within a test case class, or a callable object which returns a536 # TestCase or TestSuite instance."537 #538 # What happens when the module can be found, but not the attribute?539 def test_loadTestsFromNames__unknown_attr_name(self):540 loader = unittest2.TestLoader()541 try:542 loader.loadTestsFromNames(['unittest2.sdasfasfasdf', 'unittest2'])543 except AttributeError as e:544 self.assertEqual(545 str(e), "'module' object has no attribute 'sdasfasfasdf'")546 else:547 self.fail(548 "TestLoader.loadTestsFromNames failed to raise AttributeError")549 # "The specifier name is a ``dotted name'' that may resolve either to550 # a module, a test case class, a TestSuite instance, a test method551 # within a test case class, or a callable object which returns a552 # TestCase or TestSuite instance."553 # ...554 # "The method optionally resolves name relative to the given module"555 #556 # What happens when given an unknown attribute on a specified `module`557 # argument?558 def test_loadTestsFromNames__unknown_name_relative_1(self):559 loader = unittest2.TestLoader()560 try:561 loader.loadTestsFromNames(['sdasfasfasdf'], unittest2)562 except AttributeError as e:563 self.assertEqual(564 str(e), "'module' object has no attribute 'sdasfasfasdf'")565 else:566 self.fail(567 "TestLoader.loadTestsFromName failed to raise AttributeError")568 # "The specifier name is a ``dotted name'' that may resolve either to569 # a module, a test case class, a TestSuite instance, a test method570 # within a test case class, or a callable object which returns a571 # TestCase or TestSuite instance."572 # ...573 # "The method optionally resolves name relative to the given module"574 #575 # Do unknown attributes (relative to a provided module) still raise an576 # exception even in the presence of valid attribute names?577 def test_loadTestsFromNames__unknown_name_relative_2(self):578 loader = unittest2.TestLoader()579 try:580 loader.loadTestsFromNames(['TestCase', 'sdasfasfasdf'], unittest2)581 except AttributeError as e:582 self.assertEqual(583 str(e), "'module' object has no attribute 'sdasfasfasdf'")584 else:585 self.fail(586 "TestLoader.loadTestsFromName failed to raise AttributeError")587 # "The specifier name is a ``dotted name'' that may resolve either to588 # a module, a test case class, a TestSuite instance, a test method589 # within a test case class, or a callable object which returns a590 # TestCase or TestSuite instance."591 # ...592 # "The method optionally resolves name relative to the given module"593 #594 # What happens when faced with the empty string?595 #596 # XXX This currently raises AttributeError, though ValueError is probably597 # more appropriate598 def test_loadTestsFromNames__relative_empty_name(self):599 loader = unittest2.TestLoader()600 try:601 loader.loadTestsFromNames([''], unittest2)602 except AttributeError:603 pass604 else:605 self.fail("Failed to raise ValueError")606 # "The specifier name is a ``dotted name'' that may resolve either to607 # a module, a test case class, a TestSuite instance, a test method608 # within a test case class, or a callable object which returns a609 # TestCase or TestSuite instance."610 # ...611 # "The method optionally resolves name relative to the given module"612 #613 # What happens when presented with an impossible attribute name?614 def test_loadTestsFromNames__relative_malformed_name(self):615 loader = unittest2.TestLoader()616 # XXX Should this raise AttributeError or ValueError?617 try:618 loader.loadTestsFromNames(['abc () //'], unittest2)619 except AttributeError:620 pass621 except ValueError:622 pass623 else:624 self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")625 # "The method optionally resolves name relative to the given module"626 #627 # Does loadTestsFromNames() make sure the provided `module` is in fact628 # a module?629 #630 # XXX This validation is currently not done. This flexibility should631 # either be documented or a TypeError should be raised.632 def test_loadTestsFromNames__relative_not_a_module(self):633 class MyTestCase(unittest2.TestCase):634 def test(self):635 pass636 class NotAModule(object):637 test_2 = MyTestCase638 loader = unittest2.TestLoader()639 suite = loader.loadTestsFromNames(['test_2'], NotAModule)640 reference = [unittest2.TestSuite([MyTestCase('test')])]641 self.assertEqual(list(suite), reference)642 # "The specifier name is a ``dotted name'' that may resolve either to643 # a module, a test case class, a TestSuite instance, a test method644 # within a test case class, or a callable object which returns a645 # TestCase or TestSuite instance."646 #647 # Does it raise an exception if the name resolves to an invalid648 # object?649 def test_loadTestsFromNames__relative_bad_object(self):650 m = types.ModuleType('m')651 m.testcase_1 = object()652 loader = unittest2.TestLoader()653 try:654 loader.loadTestsFromNames(['testcase_1'], m)655 except TypeError:656 pass657 else:658 self.fail("Should have raised TypeError")659 # "The specifier name is a ``dotted name'' that may resolve ... to660 # ... a test case class"661 def test_loadTestsFromNames__relative_TestCase_subclass(self):662 m = types.ModuleType('m')663 class MyTestCase(unittest2.TestCase):664 def test(self):665 pass666 m.testcase_1 = MyTestCase667 loader = unittest2.TestLoader()668 suite = loader.loadTestsFromNames(['testcase_1'], m)669 self.assertIsInstance(suite, loader.suiteClass)670 expected = loader.suiteClass([MyTestCase('test')])671 self.assertEqual(list(suite), [expected])672 # "The specifier name is a ``dotted name'' that may resolve ... to673 # ... a TestSuite instance"674 def test_loadTestsFromNames__relative_TestSuite(self):675 m = types.ModuleType('m')676 class MyTestCase(unittest2.TestCase):677 def test(self):678 pass679 m.testsuite = unittest2.TestSuite([MyTestCase('test')])680 loader = unittest2.TestLoader()681 suite = loader.loadTestsFromNames(['testsuite'], m)682 self.assertIsInstance(suite, loader.suiteClass)683 self.assertEqual(list(suite), [m.testsuite])684 # "The specifier name is a ``dotted name'' that may resolve ... to ... a685 # test method within a test case class"686 def test_loadTestsFromNames__relative_testmethod(self):687 m = types.ModuleType('m')688 class MyTestCase(unittest2.TestCase):689 def test(self):690 pass691 m.testcase_1 = MyTestCase692 loader = unittest2.TestLoader()693 suite = loader.loadTestsFromNames(['testcase_1.test'], m)694 self.assertIsInstance(suite, loader.suiteClass)695 ref_suite = unittest2.TestSuite([MyTestCase('test')])696 self.assertEqual(list(suite), [ref_suite])697 # "The specifier name is a ``dotted name'' that may resolve ... to ... a698 # test method within a test case class"699 #700 # Does the method gracefully handle names that initially look like they701 # resolve to "a test method within a test case class" but don't?702 def test_loadTestsFromNames__relative_invalid_testmethod(self):703 m = types.ModuleType('m')704 class MyTestCase(unittest2.TestCase):705 def test(self):706 pass707 m.testcase_1 = MyTestCase708 loader = unittest2.TestLoader()709 try:710 loader.loadTestsFromNames(['testcase_1.testfoo'], m)711 except AttributeError as e:712 self.assertEqual(713 str(e), "type object 'MyTestCase' has no attribute 'testfoo'")714 else:715 self.fail("Failed to raise AttributeError")716 # "The specifier name is a ``dotted name'' that may resolve ... to717 # ... a callable object which returns a ... TestSuite instance"718 def test_loadTestsFromNames__callable__TestSuite(self):719 m = types.ModuleType('m')720 testcase_1 = unittest2.FunctionTestCase(lambda: None)721 testcase_2 = unittest2.FunctionTestCase(lambda: None)722 def return_TestSuite():723 return unittest2.TestSuite([testcase_1, testcase_2])724 m.return_TestSuite = return_TestSuite725 loader = unittest2.TestLoader()726 suite = loader.loadTestsFromNames(['return_TestSuite'], m)727 self.assertIsInstance(suite, loader.suiteClass)728 expected = unittest2.TestSuite([testcase_1, testcase_2])729 self.assertEqual(list(suite), [expected])730 # "The specifier name is a ``dotted name'' that may resolve ... to731 # ... a callable object which returns a TestCase ... instance"732 def test_loadTestsFromNames__callable__TestCase_instance(self):733 m = types.ModuleType('m')734 testcase_1 = unittest2.FunctionTestCase(lambda: None)735 def return_TestCase():736 return testcase_1737 m.return_TestCase = return_TestCase738 loader = unittest2.TestLoader()739 suite = loader.loadTestsFromNames(['return_TestCase'], m)740 self.assertIsInstance(suite, loader.suiteClass)741 ref_suite = unittest2.TestSuite([testcase_1])742 self.assertEqual(list(suite), [ref_suite])743 # "The specifier name is a ``dotted name'' that may resolve ... to744 # ... a callable object which returns a TestCase or TestSuite instance"745 #746 # Are staticmethods handled correctly?747 def test_loadTestsFromNames__callable__call_staticmethod(self):748 m = types.ModuleType('m')749 class Test1(unittest2.TestCase):750 def test(self):751 pass752 testcase_1 = Test1('test')753 class Foo(unittest2.TestCase):754 @staticmethod755 def foo():756 return testcase_1757 m.Foo = Foo758 loader = unittest2.TestLoader()759 suite = loader.loadTestsFromNames(['Foo.foo'], m)760 self.assertIsInstance(suite, loader.suiteClass)761 ref_suite = unittest2.TestSuite([testcase_1])762 self.assertEqual(list(suite), [ref_suite])763 # "The specifier name is a ``dotted name'' that may resolve ... to764 # ... a callable object which returns a TestCase or TestSuite instance"765 #766 # What happens when the callable returns something else?767 def test_loadTestsFromNames__callable__wrong_type(self):768 m = types.ModuleType('m')769 def return_wrong():770 return 6771 m.return_wrong = return_wrong772 loader = unittest2.TestLoader()773 try:774 loader.loadTestsFromNames(['return_wrong'], m)775 except TypeError:776 pass777 else:778 self.fail("TestLoader.loadTestsFromNames failed to raise TypeError")779 # "The specifier can refer to modules and packages which have not been780 # imported; they will be imported as a side-effect"781 def test_loadTestsFromNames__module_not_loaded(self):782 # We're going to try to load this module as a side-effect, so it783 # better not be loaded before we try.784 #785 module_name = 'unittest2.test.dummy'786 sys.modules.pop(module_name, None)787 loader = unittest2.TestLoader()788 try:789 suite = loader.loadTestsFromNames([module_name])790 self.assertIsInstance(suite, loader.suiteClass)791 self.assertEqual(list(suite), [unittest2.TestSuite()])792 # module should now be loaded, thanks to loadTestsFromName()793 self.assertIn(module_name, sys.modules)794 finally:795 if module_name in sys.modules:796 del sys.modules[module_name]797 ################################################################798 # /Tests for TestLoader.loadTestsFromNames()799 # Tests for TestLoader.getTestCaseNames()800 ################################################################801 # "Return a sorted sequence of method names found within testCaseClass"802 #803 # Test.foobar is defined to make sure getTestCaseNames() respects804 # loader.testMethodPrefix805 def test_getTestCaseNames(self):806 class Test(unittest2.TestCase):807 def test_1(self): pass808 def test_2(self): pass809 def foobar(self): pass810 loader = unittest2.TestLoader()811 self.assertEqual(loader.getTestCaseNames(Test), ['test_1', 'test_2'])812 # "Return a sorted sequence of method names found within testCaseClass"813 #814 # Does getTestCaseNames() behave appropriately if no tests are found?815 def test_getTestCaseNames__no_tests(self):816 class Test(unittest2.TestCase):817 def foobar(self): pass818 loader = unittest2.TestLoader()819 self.assertEqual(loader.getTestCaseNames(Test), [])820 # "Return a sorted sequence of method names found within testCaseClass"821 #822 # Are not-TestCases handled gracefully?823 #824 # XXX This should raise a TypeError, not return a list825 #826 # XXX It's too late in the 2.5 release cycle to fix this, but it should827 # probably be revisited for 2.6828 def test_getTestCaseNames__not_a_TestCase(self):829 class BadCase(int):830 def test_foo(self):831 pass832 loader = unittest2.TestLoader()833 names = loader.getTestCaseNames(BadCase)834 self.assertEqual(names, ['test_foo'])835 # "Return a sorted sequence of method names found within testCaseClass"836 #837 # Make sure inherited names are handled.838 #839 # TestP.foobar is defined to make sure getTestCaseNames() respects840 # loader.testMethodPrefix841 def test_getTestCaseNames__inheritance(self):842 class TestP(unittest2.TestCase):843 def test_1(self): pass844 def test_2(self): pass845 def foobar(self): pass846 class TestC(TestP):847 def test_1(self): pass848 def test_3(self): pass849 loader = unittest2.TestLoader()850 names = ['test_1', 'test_2', 'test_3']851 self.assertEqual(loader.getTestCaseNames(TestC), names)852 ################################################################853 # /Tests for TestLoader.getTestCaseNames()854 # Tests for TestLoader.testMethodPrefix855 ################################################################856 # "String giving the prefix of method names which will be interpreted as857 # test methods"858 #859 # Implicit in the documentation is that testMethodPrefix is respected by860 # all loadTestsFrom* methods.861 def test_testMethodPrefix__loadTestsFromTestCase(self):862 class Foo(unittest2.TestCase):863 def test_1(self): pass864 def test_2(self): pass865 def foo_bar(self): pass866 tests_1 = unittest2.TestSuite([Foo('foo_bar')])867 tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])868 loader = unittest2.TestLoader()869 loader.testMethodPrefix = 'foo'870 self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_1)871 loader.testMethodPrefix = 'test'872 self.assertEqual(loader.loadTestsFromTestCase(Foo), tests_2)873 # "String giving the prefix of method names which will be interpreted as874 # test methods"875 #876 # Implicit in the documentation is that testMethodPrefix is respected by877 # all loadTestsFrom* methods.878 def test_testMethodPrefix__loadTestsFromModule(self):879 m = types.ModuleType('m')880 class Foo(unittest2.TestCase):881 def test_1(self): pass882 def test_2(self): pass883 def foo_bar(self): pass884 m.Foo = Foo885 tests_1 = [unittest2.TestSuite([Foo('foo_bar')])]886 tests_2 = [unittest2.TestSuite([Foo('test_1'), Foo('test_2')])]887 loader = unittest2.TestLoader()888 loader.testMethodPrefix = 'foo'889 self.assertEqual(list(loader.loadTestsFromModule(m)), tests_1)890 loader.testMethodPrefix = 'test'891 self.assertEqual(list(loader.loadTestsFromModule(m)), tests_2)892 # "String giving the prefix of method names which will be interpreted as893 # test methods"894 #895 # Implicit in the documentation is that testMethodPrefix is respected by896 # all loadTestsFrom* methods.897 def test_testMethodPrefix__loadTestsFromName(self):898 m = types.ModuleType('m')899 class Foo(unittest2.TestCase):900 def test_1(self): pass901 def test_2(self): pass902 def foo_bar(self): pass903 m.Foo = Foo904 tests_1 = unittest2.TestSuite([Foo('foo_bar')])905 tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])906 loader = unittest2.TestLoader()907 loader.testMethodPrefix = 'foo'908 self.assertEqual(loader.loadTestsFromName('Foo', m), tests_1)909 loader.testMethodPrefix = 'test'910 self.assertEqual(loader.loadTestsFromName('Foo', m), tests_2)911 # "String giving the prefix of method names which will be interpreted as912 # test methods"913 #914 # Implicit in the documentation is that testMethodPrefix is respected by915 # all loadTestsFrom* methods.916 def test_testMethodPrefix__loadTestsFromNames(self):917 m = types.ModuleType('m')918 class Foo(unittest2.TestCase):919 def test_1(self): pass920 def test_2(self): pass921 def foo_bar(self): pass922 m.Foo = Foo923 tests_1 = unittest2.TestSuite([unittest2.TestSuite([Foo('foo_bar')])])924 tests_2 = unittest2.TestSuite([Foo('test_1'), Foo('test_2')])925 tests_2 = unittest2.TestSuite([tests_2])926 loader = unittest2.TestLoader()927 loader.testMethodPrefix = 'foo'928 self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests_1)929 loader.testMethodPrefix = 'test'930 self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests_2)931 # "The default value is 'test'"932 def test_testMethodPrefix__default_value(self):933 loader = unittest2.TestLoader()934 self.assertTrue(loader.testMethodPrefix == 'test')935 ################################################################936 # /Tests for TestLoader.testMethodPrefix937 # Tests for TestLoader.sortTestMethodsUsing938 ################################################################939 # "Function to be used to compare method names when sorting them in940 # getTestCaseNames() and all the loadTestsFromX() methods"941 def test_sortTestMethodsUsing__loadTestsFromTestCase(self):942 class Foo(unittest2.TestCase):943 def test_1(self): pass944 def test_2(self): pass945 loader = unittest2.TestLoader()946 loader.sortTestMethodsUsing = unittest2.reversed_cmp_947 tests = loader.suiteClass([Foo('test_2'), Foo('test_1')])948 self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)949 # "Function to be used to compare method names when sorting them in950 # getTestCaseNames() and all the loadTestsFromX() methods"951 def test_sortTestMethodsUsing__loadTestsFromModule(self):952 m = types.ModuleType('m')953 class Foo(unittest2.TestCase):954 def test_1(self): pass955 def test_2(self): pass956 m.Foo = Foo957 loader = unittest2.TestLoader()958 loader.sortTestMethodsUsing = unittest2.reversed_cmp_959 tests = [loader.suiteClass([Foo('test_2'), Foo('test_1')])]960 self.assertEqual(list(loader.loadTestsFromModule(m)), tests)961 # "Function to be used to compare method names when sorting them in962 # getTestCaseNames() and all the loadTestsFromX() methods"963 def test_sortTestMethodsUsing__loadTestsFromName(self):964 m = types.ModuleType('m')965 class Foo(unittest2.TestCase):966 def test_1(self): pass967 def test_2(self): pass968 m.Foo = Foo969 loader = unittest2.TestLoader()970 loader.sortTestMethodsUsing = unittest2.reversed_cmp_971 tests = loader.suiteClass([Foo('test_2'), Foo('test_1')])972 self.assertEqual(loader.loadTestsFromName('Foo', m), tests)973 # "Function to be used to compare method names when sorting them in974 # getTestCaseNames() and all the loadTestsFromX() methods"975 def test_sortTestMethodsUsing__loadTestsFromNames(self):976 m = types.ModuleType('m')977 class Foo(unittest2.TestCase):978 def test_1(self): pass979 def test_2(self): pass980 m.Foo = Foo981 loader = unittest2.TestLoader()982 loader.sortTestMethodsUsing = unittest2.reversed_cmp_983 tests = [loader.suiteClass([Foo('test_2'), Foo('test_1')])]984 self.assertEqual(list(loader.loadTestsFromNames(['Foo'], m)), tests)985 # "Function to be used to compare method names when sorting them in986 # getTestCaseNames()"987 #988 # Does it actually affect getTestCaseNames()?989 def test_sortTestMethodsUsing__getTestCaseNames(self):990 class Foo(unittest2.TestCase):991 def test_1(self): pass992 def test_2(self): pass993 loader = unittest2.TestLoader()994 loader.sortTestMethodsUsing = unittest2.reversed_cmp_995 test_names = ['test_2', 'test_1']996 self.assertEqual(loader.getTestCaseNames(Foo), test_names)997 # "The default value is the built-in cmp() function"998 def test_sortTestMethodsUsing__default_value(self):999 loader = unittest2.TestLoader()1000 self.assertTrue(loader.sortTestMethodsUsing is unittest2.cmp_)1001 # "it can be set to None to disable the sort."1002 #1003 # XXX How is this different from reassigning cmp? Are the tests returned1004 # in a random order or something? This behaviour should die1005 def test_sortTestMethodsUsing__None(self):1006 class Foo(unittest2.TestCase):1007 def test_1(self): pass1008 def test_2(self): pass1009 loader = unittest2.TestLoader()1010 loader.sortTestMethodsUsing = None1011 test_names = ['test_2', 'test_1']1012 self.assertEqual(set(loader.getTestCaseNames(Foo)), set(test_names))1013 ################################################################1014 # /Tests for TestLoader.sortTestMethodsUsing1015 # Tests for TestLoader.suiteClass1016 ################################################################1017 # "Callable object that constructs a test suite from a list of tests."1018 def test_suiteClass__loadTestsFromTestCase(self):1019 class Foo(unittest2.TestCase):1020 def test_1(self): pass1021 def test_2(self): pass1022 def foo_bar(self): pass1023 tests = [Foo('test_1'), Foo('test_2')]1024 loader = unittest2.TestLoader()1025 loader.suiteClass = list1026 self.assertEqual(loader.loadTestsFromTestCase(Foo), tests)1027 # It is implicit in the documentation for TestLoader.suiteClass that1028 # all TestLoader.loadTestsFrom* methods respect it. Let's make sure1029 def test_suiteClass__loadTestsFromModule(self):1030 m = types.ModuleType('m')1031 class Foo(unittest2.TestCase):1032 def test_1(self): pass1033 def test_2(self): pass1034 def foo_bar(self): pass1035 m.Foo = Foo1036 tests = [[Foo('test_1'), Foo('test_2')]]1037 loader = unittest2.TestLoader()1038 loader.suiteClass = list1039 self.assertEqual(loader.loadTestsFromModule(m), tests)1040 # It is implicit in the documentation for TestLoader.suiteClass that1041 # all TestLoader.loadTestsFrom* methods respect it. Let's make sure1042 def test_suiteClass__loadTestsFromName(self):1043 m = types.ModuleType('m')1044 class Foo(unittest2.TestCase):1045 def test_1(self): pass1046 def test_2(self): pass1047 def foo_bar(self): pass1048 m.Foo = Foo1049 tests = [Foo('test_1'), Foo('test_2')]1050 loader = unittest2.TestLoader()1051 loader.suiteClass = list1052 self.assertEqual(loader.loadTestsFromName('Foo', m), tests)1053 # It is implicit in the documentation for TestLoader.suiteClass that1054 # all TestLoader.loadTestsFrom* methods respect it. Let's make sure1055 def test_suiteClass__loadTestsFromNames(self):1056 m = types.ModuleType('m')1057 class Foo(unittest2.TestCase):1058 def test_1(self): pass1059 def test_2(self): pass1060 def foo_bar(self): pass1061 m.Foo = Foo1062 tests = [[Foo('test_1'), Foo('test_2')]]1063 loader = unittest2.TestLoader()1064 loader.suiteClass = list1065 self.assertEqual(loader.loadTestsFromNames(['Foo'], m), tests)1066 # "The default value is the TestSuite class"1067 def test_suiteClass__default_value(self):1068 loader = unittest2.TestLoader()1069 self.assertTrue(loader.suiteClass is unittest2.TestSuite)1070if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!