Best Python code snippet using stestr_python
test_testsuite.py
Source:test_testsuite.py
...55 ], wrap_log)56 # Smoke test to make sure everything ran OK.57 self.assertNotEqual([], result_log)58 def split_suite(self, suite):59 tests = list(iterate_tests(suite))60 return tests[0], tests[1]61class TestFixtureSuite(TestCase):62 def setUp(self):63 super(TestFixtureSuite, self).setUp()64 if FunctionFixture is None:65 self.skip("Need fixtures")66 def test_fixture_suite(self):67 log = []68 class Sample(TestCase):69 def test_one(self):70 log.append(1)71 def test_two(self):72 log.append(2)73 fixture = FunctionFixture(74 lambda: log.append('setUp'),75 lambda fixture: log.append('tearDown'))76 suite = FixtureSuite(fixture, [Sample('test_one'), Sample('test_two')])77 suite.run(LoggingResult([]))78 self.assertEqual(['setUp', 1, 2, 'tearDown'], log)79class TestSortedTests(TestCase):80 def test_sorts_custom_suites(self):81 a = PlaceHolder('a')82 b = PlaceHolder('b')83 class Subclass(unittest.TestSuite):84 def sort_tests(self):85 self._tests = sorted_tests(self, True)86 input_suite = Subclass([b, a])87 suite = sorted_tests(input_suite)88 self.assertEqual([a, b], list(iterate_tests(suite)))89 self.assertEqual([input_suite], list(iter(suite)))90 def test_custom_suite_without_sort_tests_works(self):91 a = PlaceHolder('a')92 b = PlaceHolder('b')93 class Subclass(unittest.TestSuite):pass94 input_suite = Subclass([b, a])95 suite = sorted_tests(input_suite)96 self.assertEqual([b, a], list(iterate_tests(suite)))97 self.assertEqual([input_suite], list(iter(suite)))98 def test_sorts_simple_suites(self):99 a = PlaceHolder('a')100 b = PlaceHolder('b')101 suite = sorted_tests(unittest.TestSuite([b, a]))102 self.assertEqual([a, b], list(iterate_tests(suite)))103def test_suite():104 from unittest import TestLoader...
run_tests.py
Source:run_tests.py
...3import __init__4from unittest import TestLoader, runner, TestSuite5this_dir = os.path.dirname(__file__)6dirs = ["pagemodel", "addon", "libdict"]7def iterate_tests(test_suite_or_case):8 """Iterate through all of the test cases in 'test_suite_or_case'."""9 try:10 suite = iter(test_suite_or_case)11 except TypeError:12 yield test_suite_or_case13 else:14 for test in suite:15 for subtest in iterate_tests(test):16 yield subtest17loader = TestLoader()18tests = TestSuite([loader.discover(os.path.join(this_dir, d), top_level_dir=this_dir) for d in dirs])19test_runner = runner.TextTestRunner()20def run_light():21 lighttests = []22 for test in iterate_tests(tests):23 if hasattr(test, "is_heavy") and test.is_heavy:24 pass25 else:26 lighttests.append(test)27 lighttests = TestSuite(lighttests)28 test_runner.run(lighttests)29def run_heavy():30 test_runner.run(tests)31def main():32 from optparse import OptionParser33 parser = OptionParser()34 parser.add_option("-l", "--heavy",35 action="store_true", dest="heavy", default=False,36 help="run heavy tests also")...
utils.py
Source:utils.py
1# Copyright (c) 2008-2010 testtools developers. See LICENSE for details.2"""Utilities for dealing with stuff in unittest.3Legacy - deprecated - use testtools.testsuite.iterate_tests4"""5import warnings6warnings.warn("Please import iterate_tests from testtools.testsuite - "7 "testtools.utils is deprecated.", DeprecationWarning, stacklevel=2)...
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!!