Best Python code snippet using lisa_python
test_lisa_runner.py
Source:test_lisa_runner.py
...45 __skipped_no_env = "no available environment"46 def setUp(self) -> None:47 lisa.environment._global_environment_id = 048 def tearDown(self) -> None:49 test_testsuite.cleanup_cases_metadata() # Necessary side effects!50 def test_merge_req_create_on_new(self) -> None:51 # if no predefined envs, can generate from requirement52 env_runbook = generate_env_runbook(is_single_env=False)53 envs = load_environments(env_runbook)54 self.assertListEqual(55 [],56 [x for x in envs],57 )58 runner = generate_runner(None)59 test_results = test_testsuite.generate_cases_result()60 runner._merge_test_requirements(61 test_results=test_results,62 existing_environments=envs,63 platform_type=constants.PLATFORM_MOCK,...
test_testsuite.py
Source:test_testsuite.py
...94 assert_that(variables).described_as("variable must not exists").is_empty()95class MockTestSuite2(TestSuite):96 def mock_ut3(self, *args: Any, **kwargs: Any) -> None:97 ...98def cleanup_cases_metadata() -> None:99 get_cases_metadata().clear()100 get_suites_metadata().clear()101def generate_cases_metadata() -> List[TestCaseMetadata]:102 ut_cases = [103 TestCaseMetadata(104 "ut1",105 0,106 requirement=simple_requirement(min_count=2),107 ),108 TestCaseMetadata("ut2", 1),109 TestCaseMetadata("ut3", 2),110 ]111 suite_metadata1 = TestSuiteMetadata("a1", "c1", "des1", ["t1", "t2"])112 suite_metadata1(MockTestSuite)113 ut_cases[0](MockTestSuite.mock_ut1)114 ut_cases[1](MockTestSuite.mock_ut2)115 suite_metadata2 = TestSuiteMetadata(116 "a2",117 "c2",118 "des2",119 ["t2", "t3"],120 requirement=node_requirement(node=schema.NodeSpace(core_count=8)),121 )122 suite_metadata2(MockTestSuite2)123 ut_cases[2](MockTestSuite2.mock_ut3)124 return ut_cases125def generate_cases_result() -> List[TestResult]:126 case_metadata = generate_cases_metadata()127 case_results = [TestResult("0", TestCaseRuntimeData(x)) for x in case_metadata]128 return case_results129def select_and_check(130 ut: TestCase, case_runbook: List[Any], expected_descriptions: List[str]131) -> List[TestCaseRuntimeData]:132 runbook = RunbookBuilder._validate_and_load({constants.TESTCASE: case_runbook})133 case_metadata = generate_cases_metadata()134 runbook.testcase = parse_testcase_filters(runbook.testcase_raw)135 filters = cast(List[schema.TestCase], runbook.testcase)136 selected = select_testcases(filters, case_metadata)137 ut.assertListEqual(expected_descriptions, [case.description for case in selected])138 return selected139class TestSuiteTestCase(TestCase):140 def generate_suite_instance(self) -> MockTestSuite:141 case_results = generate_cases_result()142 self.case_results = case_results[:2]143 suite_metadata = case_results[0].runtime_data.metadata.suite144 runbook = generate_runbook(is_single_env=True, local=True, remote=True)145 envs = load_environments(runbook)146 self.default_env = list(envs.values())[0]147 assert self.default_env148 test_suite = MockTestSuite(149 metadata=suite_metadata,150 )151 return test_suite152 def setUp(self) -> None:153 cleanup_cases_metadata()154 def test_expanded_nodespace(self) -> None:155 cases = generate_cases_metadata()156 for case in cases:157 self.assertIsNotNone(case.requirement)158 assert case.requirement.environment159 for node in case.requirement.environment.nodes:160 self.assertEqual(161 1, node.node_count, "node count should be expanded to 1"162 )163 def test_case_override_suite(self) -> None:164 cases = generate_cases_metadata()165 case1_found = False166 case2_found = False167 for case in cases:...
test_testselector.py
Source:test_testselector.py
...4from lisa import LisaException, constants5from selftests.test_testsuite import cleanup_cases_metadata, select_and_check6class SelectorTestCase(TestCase):7 def setUp(self) -> None:8 cleanup_cases_metadata()9 def test_no_case_selected(self) -> None:10 runbook = [{constants.TESTCASE_CRITERIA: {"area": "demo"}}]11 select_and_check(self, runbook, [])12 def test_select_by_priority(self) -> None:13 runbook = [{constants.TESTCASE_CRITERIA: {"priority": 0}}]14 select_and_check(self, runbook, ["ut1"])15 def test_select_by_tag(self) -> None:16 runbook = [{constants.TESTCASE_CRITERIA: {"tags": "t1"}}]17 select_and_check(self, runbook, ["ut1", "ut2"])18 def test_select_by_one_of_tag(self) -> None:19 runbook = [{constants.TESTCASE_CRITERIA: {"tags": ["t1", "t3"]}}]20 select_and_check(self, runbook, ["ut1", "ut2", "ut3"])21 def test_select_by_two_rules(self) -> None:22 runbook = [{constants.TESTCASE_CRITERIA: {"tags": ["t1", "t3"], "area": "a1"}}]...
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!!