Best Python code snippet using lemoncheesecake
test_cmd_top.py
Source:test_cmd_top.py
...49 assert "suite2" in lines[4]50def test_top_suites_cmd_test_run_in_progress(report_in_progress_path, cmdout):51 assert main(["top-suites", report_in_progress_path]) == 052 cmdout.dump()53 cmdout.assert_substrs_anywhere(["suite"])54def test_get_top_tests():55 report = make_report([56 make_suite_result("suite1", tests=[make_test_result("test", start_time=0.0, end_time=1.0)]),57 make_suite_result("suite2", tests=[make_test_result("test", start_time=1.0, end_time=4.0)]),58 ])59 top_suites = TopTests.get_top_tests(report, ResultFilter())60 assert len(top_suites) == 261 assert top_suites[0][0] == "suite2.test"62 assert top_suites[0][1] == "3.000s"63 assert top_suites[0][2] == "75%"64 assert top_suites[1][0] == "suite1.test"65 assert top_suites[1][1] == "1.000s"66 assert top_suites[1][2] == "25%"67def test_top_tests_cmd(tmpdir, cmdout):68 report = make_report([69 make_suite_result("suite1", tests=[make_test_result("test", start_time=0.1, end_time=1.0)]),70 make_suite_result("suite2", tests=[make_test_result("test", start_time=1.0, end_time=4.0)]),71 ])72 report_path = tmpdir.join("report.json").strpath73 save_report_into_file(report, report_path)74 assert main(["top-tests", report_path]) == 075 lines = cmdout.get_lines()76 assert "suite2.test" in lines[4]77def test_top_tests_cmd_test_run_in_progress(report_in_progress_path, cmdout):78 assert main(["top-tests", report_in_progress_path]) == 079 cmdout.dump()80 cmdout.assert_substrs_anywhere(["suite.test_2"])81def test_get_top_steps():82 report = make_report([83 make_suite_result("suite1", tests=[make_test_result(steps=[84 make_step("step1", start_time=0.0, end_time=1.0),85 make_step("step1", start_time=1.0, end_time=3.0),86 ])]),87 make_suite_result("suite2", tests=[make_test_result(steps=[88 make_step("step2", start_time=3.0, end_time=4.0)89 ])]),90 ])91 top_steps = TopSteps.get_top_steps(report, StepFilter())92 assert len(top_steps) == 293 assert top_steps[0][0] == "step1"94 assert top_steps[0][1] == "2"95 assert top_steps[0][2] == "1.000s"96 assert top_steps[0][3] == "2.000s"97 assert top_steps[0][4] == "1.500s"98 assert top_steps[0][5] == "3.000s"99 assert top_steps[0][6] == "75%"100 assert top_steps[1][0] == "step2"101 assert top_steps[1][1] == "1"102 assert top_steps[1][2] == "1.000s"103 assert top_steps[1][3] == "1.000s"104 assert top_steps[1][4] == "1.000s"105 assert top_steps[1][5] == "1.000s"106 assert top_steps[1][6] == "25%"107def test_get_top_steps_with_test_session_setup_and_grep():108 @lcc.fixture(scope="session")109 def fixt():110 lcc.set_step("mystep")111 lcc.log_info("foobar")112 @lcc.suite("suite")113 class suite:114 @lcc.test("test")115 def test(self, fixt):116 pass117 report = run_suite_class(suite, fixtures=[fixt])118 top_steps = TopSteps.get_top_steps(report, StepFilter(grep=re.compile("foobar")))119 assert len(top_steps) == 1120 assert top_steps[0][0] == "mystep"121def test_get_top_steps_filter_on_passed():122 @lcc.suite("suite")123 class suite:124 @lcc.test("test")125 def test(self):126 lcc.set_step("something ok")127 lcc.log_info("info")128 lcc.set_step("something not ok")129 lcc.log_error("error")130 report = run_suite_class(suite)131 top_steps = TopSteps.get_top_steps(report, StepFilter(passed=True))132 assert len(top_steps) == 1133 assert top_steps[0][0] == "something ok"134def test_get_top_steps_filter_on_grep():135 @lcc.suite("suite")136 class suite:137 @lcc.test("test")138 def test(self):139 lcc.set_step("something ok")140 lcc.log_info("info")141 lcc.set_step("something not ok")142 lcc.log_error("error")143 report = run_suite_class(suite)144 top_steps = TopSteps.get_top_steps(report, StepFilter(grep=re.compile("error")))145 assert len(top_steps) == 1146 assert top_steps[0][0] == "something not ok"147def test_top_steps_cmd(tmpdir, cmdout):148 report = make_report([149 make_suite_result("suite1", tests=[150 make_test_result(steps=[make_step("step1", start_time=0.1, end_time=1.0)])151 ])152 ])153 report_path = tmpdir.join("report.json").strpath154 save_report_into_file(report, report_path)155 assert main(["top-steps", report_path]) == 0156 lines = cmdout.get_lines()157 assert "step1" in lines[4]158def test_top_steps_cmd_test_run_in_progress(report_in_progress_path, cmdout):159 assert main(["top-steps", report_in_progress_path]) == 0160 cmdout.dump()...
test_cmd_report.py
Source:test_cmd_report.py
...82 cmdout.assert_lines_nb(9)83def test_report_test_run_in_progress(report_in_progress_path, cmdout):84 assert main(["report", report_in_progress_path]) == 085 cmdout.dump()86 cmdout.assert_substrs_anywhere(["suite.test_1"])87 cmdout.assert_substrs_anywhere(["step"])88 cmdout.assert_substrs_anywhere(["message"])89def test_report_without_debug_arg(tmpdir, cmdout):90 run_suite_class(suite_with_debug, tmpdir=tmpdir, backends=[JsonBackend()])91 assert main(["report", tmpdir.strpath]) == 092 cmdout.dump()93 cmdout.assert_substrs_anywhere(["step 1"])94 cmdout.assert_substrs_anywhere(["1_info_message"])95 cmdout.assert_substrs_nowhere(["1_debug_message"])96 cmdout.assert_substrs_nowhere(["step 2"])97 cmdout.assert_substrs_nowhere(["2_debug_message"])98def test_report_with_debug_arg(tmpdir, cmdout):99 run_suite_class(suite_with_debug, tmpdir=tmpdir, backends=[JsonBackend()])100 assert main(["report", tmpdir.strpath, "--debug"]) == 0101 cmdout.dump()102 cmdout.assert_substrs_anywhere(["step 1"])103 cmdout.assert_substrs_anywhere(["1_info_message"])104 cmdout.assert_substrs_anywhere(["1_debug_message"])105 cmdout.assert_substrs_anywhere(["step 2"])...
cli.py
Source:cli.py
...15 def assert_substrs_in_line(self, line_nb, substrs, on_stderr=False):16 lines = self.get_lines(on_stderr)17 for substr in substrs:18 assert substr in lines[line_nb]19 def assert_substrs_anywhere(self, substrs, on_stderr=False):20 for line_nb in range(len(self.get_lines(on_stderr))):21 try:22 self.assert_substrs_in_line(line_nb, substrs, on_stderr)23 except AssertionError:24 pass25 else:26 return27 else:28 raise AssertionError()29 def assert_substrs_nowhere(self, substrs, on_stderr=False):30 with pytest.raises(AssertionError):31 self.assert_substrs_anywhere(substrs, on_stderr)32 def assert_substrs_not_in_line(self, line_nb, substrs, on_stderr=False):33 lines = self.get_lines(on_stderr)34 for substr in substrs:35 assert substr not in lines[line_nb]36 def assert_line_startswith(self, line_nb, substr, on_stderr=False):37 lines = self.get_lines(on_stderr)38 assert lines[line_nb].startswith(substr)39 def assert_line_not_startswith(self, line_nb, substr, on_stderr=False):40 lines = self.get_lines(on_stderr)41 assert not lines[line_nb].startswith(substr)42 def assert_lines_nb(self, lines_nb, on_stderr=False):43 lines = self.get_lines(on_stderr)44 assert len(lines) == lines_nb45 def assert_lines_match(self, pattern, on_stderr=False):...
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!!