How to use run_suite_class method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_runner.py

Source:test_runner.py Github

copy

Full Screen

...21 class MySuite:22 @lcc.test("Some test")23 def sometest(self):24 pass25 assert_test_passed(run_suite_class(MySuite))26def test_test_failure():27 @lcc.suite("MySuite")28 class MySuite:29 @lcc.test("Some test")30 def sometest(self):31 check_that("val", 1, equal_to(2))32 assert_test_failed(run_suite_class(MySuite))33def test_test_module():34 suite = build_suite_from_module("""35@lcc.test("Some test")36def sometest():37 pass38""")39 report = run_suite(suite)40 assert_test_passed(report)41def test_exception_unexpected():42 @lcc.suite("MySuite")43 class MySuite:44 @lcc.test("First test")45 def first_test(self):46 1 / 047 @lcc.test("Second test")48 def second_test(self):49 pass50 assert_test_statuses(run_suite_class(MySuite), failed=["MySuite.first_test"], passed=["MySuite.second_test"])51def test_exception_aborttest():52 @lcc.suite("MySuite")53 class MySuite:54 @lcc.test("Some test")55 def sometest(self):56 raise lcc.AbortTest("test error")57 @lcc.test("Some other test")58 def someothertest(self):59 pass60 assert_test_statuses(run_suite_class(MySuite), failed=["MySuite.sometest"], passed=["MySuite.someothertest"])61def test_exception_abortsuite():62 @lcc.suite("MySuite")63 class MySuite:64 @lcc.suite("MyFirstSuite")65 class MyFirstSuite:66 @lcc.test("Some test")67 def sometest(self):68 raise lcc.AbortSuite("test error")69 @lcc.test("Some other test")70 def someothertest(self):71 pass72 @lcc.suite("MySecondSuite")73 class MySecondSuite:74 @lcc.test("Another test")75 def anothertest(self):76 pass77 assert_test_statuses(78 run_suite_class(MySuite),79 failed=["MySuite.MyFirstSuite.sometest"],80 skipped=["MySuite.MyFirstSuite.someothertest"],81 passed=["MySuite.MySecondSuite.anothertest"],82 )83def test_exception_abortalltests():84 @lcc.suite("MySuite")85 class MySuite:86 @lcc.suite("MyFirstSuite")87 class MyFirstSuite:88 @lcc.test("Some test")89 def sometest(self):90 raise lcc.AbortAllTests("test error")91 @lcc.test("Some other test")92 def someothertest(self):93 pass94 @lcc.suite("MySecondSuite")95 class MySecondSuite:96 @lcc.test("Another test")97 def anothertest(self):98 pass99 assert_test_statuses(100 run_suite_class(MySuite),101 failed=["MySuite.MyFirstSuite.sometest"],102 skipped=["MySuite.MyFirstSuite.someothertest", "MySuite.MySecondSuite.anothertest"]103 )104def test_generated_test():105 @lcc.suite("MySuite")106 class MySuite:107 def __init__(self):108 def test_func():109 lcc.log_info("somelog")110 test = lcc.Test("mytest", "My Test", test_func)111 add_test_into_suite(test, self)112 assert_test_passed(run_suite_class(MySuite))113def test_sub_suite_inline():114 @lcc.suite("MyParentSuite")115 class MyParentSuite:116 @lcc.suite("MyChildSuite")117 class MyChildSuite:118 @lcc.test("Some test")119 def sometest(self):120 pass121 assert_test_passed(run_suite_class(MyParentSuite))122def test_sub_suite_with_dir_only(tmpdir):123 tmpdir.mkdir("parent_suite")124 tmpdir.join("parent_suite").join("child_suite.py").write("""125import lemoncheesecake.api as lcc126@lcc.test()127def my_test():128 lcc.log_info("some thing")129""")130 suites = load_suites_from_directory(tmpdir.strpath)131 report = run_suites(suites)132 assert_test_statuses(report, passed=("parent_suite.child_suite.my_test",))133def test_setup_test():134 marker = []135 @lcc.suite("MySuite")136 class MySuite:137 def setup_test(self, test):138 marker.append(test.name)139 @lcc.test("Some test")140 def sometest(self):141 pass142 run_suite_class(MySuite)143 assert marker == ["sometest"]144def test_teardown_test():145 marker = []146 @lcc.suite("MySuite")147 class MySuite:148 def teardown_test(self, test, status):149 marker.append((test.name, status))150 @lcc.test("Some test")151 def sometest(self):152 pass153 run_suite_class(MySuite)154 assert marker[0] == ("sometest", "passed")155def test_teardown_test_after_test_failure():156 marker = []157 @lcc.suite("MySuite")158 class MySuite:159 def teardown_test(self, test, status):160 marker.append((test.name, status))161 @lcc.test("Some test")162 def sometest(self):163 1 / 0164 run_suite_class(MySuite)165 assert marker[0] == ("sometest", "failed")166def test_setup_suite():167 marker = []168 @lcc.suite("MySuite")169 class MySuite:170 def setup_suite(self):171 marker.append("ok")172 @lcc.test("Some test")173 def sometest(self):174 pass175 run_suite_class(MySuite)176 assert marker177def test_setup_suite_with_disabled_test():178 marker = []179 @lcc.suite("suite_1")180 class suite_1:181 def setup_suite(self):182 marker.append("ok")183 @lcc.test("test")184 @lcc.disabled()185 def test(self):186 pass187 @lcc.suite("suite_2")188 class suite_2:189 @lcc.test("test")190 def test(self):191 pass192 report = run_suite_classes((suite_1, suite_2))193 assert_test_statuses(report, disabled=["suite_1.test"], passed=["suite_2.test"])194 assert not marker195def test_setup_suite_with_disabled_test_and_force_disabled():196 marker = []197 @lcc.suite("suite_1")198 class suite_1:199 def setup_suite(self):200 marker.append("ok")201 @lcc.test("test")202 @lcc.disabled()203 def test(self):204 pass205 @lcc.suite("suite_2")206 class suite_2:207 @lcc.test("test")208 def test(self):209 pass210 report = run_suite_classes((suite_1, suite_2), force_disabled=True)211 assert_test_statuses(report, passed=["suite_1.test", "suite_2.test"])212 assert marker213def test_teardown_suite():214 marker = []215 @lcc.suite("MySuite")216 class MySuite:217 def teardown_suite(self):218 marker.append("ok")219 @lcc.test("Some test")220 def sometest(self):221 pass222 run_suite_class(MySuite)223 assert marker224def test_teardown_suite_with_disabled_test():225 marker = []226 @lcc.suite("suite_1")227 class suite_1:228 @lcc.test("test")229 @lcc.disabled()230 def test(self):231 pass232 def teardown_suite(self):233 marker.append("ok")234 @lcc.suite("suite_2")235 class suite_2:236 @lcc.test("test")237 def test(self):238 pass239 report = run_suite_classes((suite_1, suite_2))240 assert_test_statuses(report, disabled=["suite_1.test"], passed=["suite_2.test"])241 assert not marker242def test_teardown_suite_with_disabled_test_and_force_disabled():243 marker = []244 @lcc.suite("suite_1")245 class suite_1:246 @lcc.test("test")247 @lcc.disabled()248 def test(self):249 pass250 def teardown_suite(self):251 marker.append("ok")252 @lcc.suite("suite_2")253 class suite_2:254 @lcc.test("test")255 def test(self):256 pass257 report = run_suite_classes((suite_1, suite_2), force_disabled=True)258 assert_test_statuses(report, passed=["suite_1.test", "suite_2.test"])259 assert marker260def test_teardown_suite_after_test_failure():261 marker = []262 @lcc.suite("MySuite")263 class MySuite:264 def teardown_suite(self):265 marker.append("ok")266 @lcc.test("Some test")267 def sometest(self):268 1 / 0269 run_suite_class(MySuite)270 assert marker271def test_teardown_suite_after_test_failure_and_test_success():272 marker = []273 @lcc.suite("MySuite")274 class MySuite:275 def teardown_suite(self):276 marker.append("teardown_suite")277 @lcc.test("Test 1")278 def test_1(self):279 marker.append("test_1")280 1 / 0281 @lcc.test("Test 2")282 def test_2(self):283 marker.append("test_2")284 run_suite_class(MySuite)285 assert marker == ["test_1", "test_2", "teardown_suite"]286def test_setup_test_error():287 marker = []288 @lcc.suite("MySuite")289 class MySuite:290 def setup_test(self, test):291 1 / 0292 @lcc.test("Some test")293 def sometest(self):294 pass295 def teardown_test(self, test, status):296 marker.append(test)297 report = run_suite_class(MySuite)298 assert_test_failed(report)299 assert len(marker) == 0300def test_setup_test_error_in_fixture():301 @lcc.fixture()302 def fix():303 1 / 0304 @lcc.suite("MySuite")305 class MySuite:306 @lcc.test("Some test")307 def sometest(self, fix):308 pass309 assert_test_failed(run_suite_class(MySuite, fixtures=[fix]))310def test_teardown_test_error():311 @lcc.suite("MySuite")312 class MySuite:313 def teardown_test(self, test, status):314 1 / 0315 @lcc.test("Some test")316 def sometest(self):317 pass318 assert_test_failed(run_suite_class(MySuite))319def test_teardown_test_error_in_fixture():320 @lcc.fixture()321 def fix():322 1 / 0323 @lcc.suite("MySuite")324 class MySuite:325 @lcc.test("Some test")326 def sometest(self, fix):327 pass328 assert_test_failed(run_suite_class(MySuite, fixtures=[fix]))329def test_setup_suite_error_and_subsuite():330 @lcc.suite("MySuite")331 class MySuite:332 def setup_suite(self):333 1 / 0334 @lcc.test("test")335 def test(self):336 pass337 @lcc.suite("MySubSuite")338 class MySubSuite:339 @lcc.test("test")340 def test(self):341 pass342 assert_test_statuses(run_suite_class(MySuite), skipped=["MySuite.test"], passed=["MySuite.MySubSuite.test"])343def test_setup_suite_error_because_of_exception():344 marker = []345 @lcc.suite("MySuite")346 class MySuite:347 def setup_suite(self):348 1 / 0349 @lcc.test("Some test")350 def sometest(self):351 pass352 def teardown_suite(self):353 marker.append("suite_teardown")354 report = run_suite_class(MySuite)355 assert_test_skipped(report)356 assert not marker357def test_setup_suite_error_because_of_error_log():358 marker = []359 @lcc.suite("MySuite")360 class MySuite:361 def setup_suite(self):362 lcc.log_error("some error")363 @lcc.test("Some test")364 def sometest(self):365 pass366 def teardown_suite(self):367 marker.append("teardown")368 report = run_suite_class(MySuite)369 assert_test_skipped(report)370 assert not marker371def test_setup_suite_error_because_of_fixture():372 marker = []373 @lcc.fixture(scope="suite")374 def fix():375 1 / 0376 @lcc.suite("MySuite")377 class MySuite:378 @lcc.test("Some test")379 def sometest(self, fix):380 pass381 @lcc.test("Some other test")382 def sometest_bis(self):383 pass384 def teardown_suite(self):385 marker.append("must_not_be_executed")386 report = run_suite_class(MySuite, fixtures=[fix])387 assert_test_statuses(report, skipped=["MySuite.sometest", "MySuite.sometest_bis"])388 assert not marker389def test_teardown_suite_error_because_of_exception():390 @lcc.suite("MySuite")391 class MySuite:392 @lcc.test("Some test")393 def sometest(self):394 pass395 def teardown_suite(self):396 1 / 0397 report = run_suite_class(MySuite)398 assert_test_passed(report)399 assert_report_node_success(report, ReportLocation.in_suite_teardown("MySuite"), expected=False)400def test_teardown_suite_error_because_of_error_log():401 @lcc.suite("MySuite")402 class MySuite:403 @lcc.test("Some test")404 def sometest(self):405 pass406 def teardown_suite(self):407 lcc.log_error("some error")408 report = run_suite_class(MySuite)409 assert_test_passed(report)410 assert_report_node_success(report, ReportLocation.in_suite_teardown("MySuite"), expected=False)411def test_teardown_suite_error_because_of_fixture():412 marker = []413 @lcc.fixture(scope="suite")414 def fix():415 yield 2416 1 / 0417 @lcc.suite("MySuite")418 class MySuite:419 @lcc.test("Some test")420 def sometest(self, fix):421 pass422 def teardown_suite(self):423 marker.append("teardown")424 report = run_suite_class(MySuite, fixtures=[fix])425 assert_test_passed(report)426 assert_report_node_success(report, ReportLocation.in_suite_teardown("MySuite"), expected=False)427 assert len(marker) == 1428def test_setup_test_session_error_because_of_exception():429 @lcc.fixture(scope="session")430 def fixt():431 1 / 0432 @lcc.suite("MySuite")433 class MySuite:434 @lcc.test("Some test")435 def sometest(self, fixt):436 pass437 @lcc.test("Some other test")438 def sometest_bis(self):439 pass440 report = run_suite_class(MySuite, fixtures=[fixt])441 assert_test_statuses(report, skipped=["MySuite.sometest", "MySuite.sometest_bis"])442 assert_report_node_success(report, ReportLocation.in_test_session_setup(), expected=False)443 test_1, test_2 = list(report.all_tests())444 assert "test session setup failed" in test_1.status_details445 assert "test session setup failed" in test_2.status_details446def test_setup_test_session_error_and_setup_suite():447 marker = []448 @lcc.suite("MySuite")449 class MySuite:450 def setup_suite(self, fixt):451 marker.append("setup_suite")452 @lcc.test("Some test")453 def sometest(self):454 pass455 @lcc.fixture(scope="session")456 def fixt():457 1 / 0458 report = run_suite_class(MySuite, fixtures=[fixt])459 assert_test_skipped(report)460 assert_report_node_success(report, ReportLocation.in_test_session_setup(), expected=False)461 assert not marker462def test_teardown_test_session_error_because_of_exception():463 @lcc.fixture(scope="session")464 def fix():465 yield 1466 1 / 0467 @lcc.suite("MySuite")468 class MySuite:469 @lcc.test("Some test")470 def sometest(self, fix):471 pass472 @lcc.test("Some other test")473 def sometest_bis(self):474 pass475 report = run_suite_class(MySuite, fixtures=[fix])476 assert_test_statuses(report, passed=["MySuite.sometest", "MySuite.sometest_bis"])477 assert_report_node_success(report, ReportLocation.in_test_session_teardown(), expected=False)478def test_teardown_test_session_after_test_failure():479 marker = []480 @lcc.fixture(scope="session")481 def fixt():482 yield 1483 marker.append(1)484 @lcc.suite("MySuite")485 class MySuite:486 @lcc.test("Some test")487 def sometest(self, fixt):488 1 / 0489 run_suite_class(MySuite, fixtures=[fixt])490 assert marker491def test_teardown_test_session_after_test_failure_and_test_success():492 marker = []493 @lcc.fixture(scope="session")494 def fixt():495 marker.append("test_session_setup")496 yield 1497 marker.append("test_session_teardown")498 @lcc.suite("MySuite")499 class MySuite:500 @lcc.test("Test 1")501 def test_1(self, fixt):502 marker.append("test_1")503 1 / 0504 @lcc.test("Test 2")505 def test_2(self):506 marker.append("test_2")507 run_suite_class(MySuite, fixtures=[fixt])508 assert marker == ["test_session_setup", "test_1", "test_2", "test_session_teardown"]509def test_pre_run_fixture_exception():510 @lcc.fixture(scope="pre_run")511 def fix():512 1 / 0513 @lcc.suite("MySuite")514 class MySuite:515 @lcc.test("Some test")516 def sometest(self, fix):517 pass518 with pytest.raises(LemoncheesecakeException) as excinfo:519 report = run_suite_class(MySuite, fixtures=[fix])520 assert "Got an unexpected" in str(excinfo.value)521 assert_test_skipped(report)522def test_pre_run_fixture_user_error():523 @lcc.fixture(scope="pre_run")524 def fix():525 raise lcc.UserError("some error")526 @lcc.suite("MySuite")527 class MySuite:528 @lcc.test("Some test")529 def sometest(self, fix):530 pass531 with pytest.raises(LemoncheesecakeException) as excinfo:532 report = run_suite_class(MySuite, fixtures=[fix])533 assert str(excinfo.value) == "some error"534 assert_test_skipped(report)535def test_pre_run_fixture_teardown_exception():536 @lcc.fixture(scope="pre_run")537 def fix():538 yield539 1 / 0540 @lcc.suite("MySuite")541 class MySuite:542 @lcc.test("Some test")543 def sometest(self, fix):544 pass545 with pytest.raises(LemoncheesecakeException) as excinfo:546 report = run_suite_class(MySuite, fixtures=[fix])547 assert "Got an unexpected" in str(excinfo.value)548 assert_test_passed(report)549def test_pre_run_fixture_teardown_user_error():550 @lcc.fixture(scope="pre_run")551 def fix():552 yield553 raise lcc.UserError("some error")554 @lcc.suite("MySuite")555 class MySuite:556 @lcc.test("Some test")557 def sometest(self, fix):558 pass559 with pytest.raises(LemoncheesecakeException) as excinfo:560 report = run_suite_class(MySuite, fixtures=[fix])561 assert str(excinfo.value) == "some error"562 assert_test_passed(report)563def test_run_with_fixture_using_test_method():564 marker = []565 @lcc.fixture()566 def test_fixture():567 return 1568 @lcc.suite("MySuite")569 class MySuite:570 @lcc.test("Test")571 def test(self, test_fixture):572 marker.append(test_fixture)573 run_suite_class(MySuite, fixtures=[test_fixture])574 assert marker == [1]575def test_run_with_fixture_using_test_function():576 @lcc.fixture()577 def test_fixture():578 return 2579 suite = build_suite_from_module("""580@lcc.test("Test")581def test(test_fixture):582 lcc.log_info(str(test_fixture))583""")584 report = run_suite(suite, fixtures=[test_fixture])585 test = next(report.all_tests())586 assert test.get_steps()[0].get_logs()[0].message == "2"587def test_run_with_fixture_with_logs():588 marker = []589 @lcc.fixture()590 def test_fixture():591 lcc.log_info("setup")592 yield 1593 lcc.log_info("teardown")594 @lcc.suite("MySuite")595 class MySuite:596 @lcc.test("Test")597 def test(self, test_fixture):598 lcc.set_step("Doing some test")599 lcc.log_info("some log")600 marker.append(test_fixture)601 report = run_suite_class(MySuite, fixtures=[test_fixture])602 assert marker == [1]603 steps = report.get_suites()[0].get_tests()[0].get_steps()604 assert len(steps) == 3605 assert steps[0].description == "Setup test"606 assert steps[1].description == "Doing some test"607 assert steps[2].description == "Teardown test"608def test_run_with_fixtures_using_yield_and_dependencies():609 marker = []610 @lcc.fixture(scope="pre_run")611 def session_fixture_prerun():612 retval = 2613 marker.append(retval)614 yield retval615 marker.append(1)616 @lcc.fixture(scope="session")617 def session_fixture(session_fixture_prerun):618 lcc.log_info("session_fixture_setup")619 retval = session_fixture_prerun * 3620 marker.append(retval)621 yield retval622 marker.append(2)623 lcc.log_info("session_fixture_teardown")624 @lcc.fixture(scope="suite")625 def suite_fixture(session_fixture):626 lcc.log_info("suite_fixture_setup")627 retval = session_fixture * 4628 marker.append(retval)629 yield retval630 marker.append(3)631 lcc.log_info("suite_fixture_teardown")632 @lcc.fixture(scope="test")633 def test_fixture(suite_fixture):634 lcc.log_info("test_fixture_setup")635 retval = suite_fixture * 5636 marker.append(retval)637 yield retval638 marker.append(4)639 lcc.log_info("test_fixture_teardown")640 @lcc.suite("MySuite")641 class MySuite:642 @lcc.test("Test")643 def test(self, test_fixture):644 marker.append(test_fixture * 6)645 report = run_suite_class(MySuite, fixtures=(session_fixture_prerun, session_fixture, suite_fixture, test_fixture))646 # test that each fixture value is passed to test or fixture requiring the fixture647 assert marker == [2, 6, 24, 120, 720, 4, 3, 2, 1]648 # check that each fixture and fixture teardown is properly executed in the right scope649 assert report.test_session_setup.get_steps()[0].get_logs()[0].message == "session_fixture_setup"650 assert report.test_session_teardown.get_steps()[0].get_logs()[0].message == "session_fixture_teardown"651 assert report.get_suites()[0].suite_setup.get_steps()[0].get_logs()[0].message == "suite_fixture_setup"652 assert report.get_suites()[0].suite_teardown.get_steps()[0].get_logs()[0].message == "suite_fixture_teardown"653 assert report.get_suites()[0].get_tests()[0].get_steps()[0].get_logs()[0].message == "test_fixture_setup"654 assert report.get_suites()[0].get_tests()[0].get_steps()[1].get_logs()[0].message == "test_fixture_teardown"655def test_run_with_fixtures_dependencies_in_test_pre_run_scope():656 # in this test, fixture dependency is set on fixture alphabetical inverse657 # order to highlight a bad dependency check implementation that use set data type658 marker = []659 @lcc.fixture(names=["fixt_3"], scope="pre_run")660 def fixt3():661 return 2662 @lcc.fixture(names=["fixt_2"], scope="pre_run")663 def fixt2(fixt_3):664 return fixt_3 * 3665 @lcc.fixture(names=["fixt_1"], scope="pre_run")666 def fixt1(fixt_2):667 return fixt_2 * 4668 @lcc.suite("MySuite")669 class MySuite:670 @lcc.test("Test")671 def test(self, fixt_1):672 marker.append(fixt_1)673 run_suite_class(MySuite, fixtures=[fixt1, fixt2, fixt3])674 assert marker == [24]675def test_run_with_fixtures_dependencies_in_test_session_scope():676 # in this test, fixture dependency is set on fixture alphabetical inverse677 # order to highlight a bad dependency check implementation that use set data type678 marker = []679 @lcc.fixture(names=["fixt_3"], scope="session")680 def fixt3():681 return 2682 @lcc.fixture(names=["fixt_2"], scope="session")683 def fixt2(fixt_3):684 return fixt_3 * 3685 @lcc.fixture(names=["fixt_1"], scope="session")686 def fixt1(fixt_2):687 return fixt_2 * 4688 @lcc.suite("MySuite")689 class MySuite:690 @lcc.test("Test")691 def test(self, fixt_1):692 marker.append(fixt_1)693 run_suite_class(MySuite, fixtures=[fixt1, fixt2, fixt3])694 assert marker == [24]695def test_run_with_fixtures_dependencies_in_suite_scope():696 # in this test, fixture dependency is set on fixture alphabetical inverse697 # order to highlight a bad dependency check implementation that use set data type698 marker = []699 @lcc.fixture(names=["fixt_3"], scope="suite")700 def fixt3():701 return 2702 @lcc.fixture(names=["fixt_2"], scope="suite")703 def fixt2(fixt_3):704 return fixt_3 * 3705 @lcc.fixture(names=["fixt_1"], scope="suite")706 def fixt1(fixt_2):707 return fixt_2 * 4708 @lcc.suite("MySuite")709 class MySuite:710 @lcc.test("Test")711 def test(self, fixt_1):712 marker.append(fixt_1)713 run_suite_class(MySuite, fixtures=[fixt1, fixt2, fixt3])714 assert marker == [24]715def test_run_with_fixtures_dependencies_in_test_scope():716 # in this test, fixture dependency is set on fixture alphabetical inverse717 # order to highlight a bad dependency check implementation that use set data type718 marker = []719 @lcc.fixture(names=["fixt_3"], scope="test")720 def fixt3():721 return 2722 @lcc.fixture(names=["fixt_2"], scope="test")723 def fixt2(fixt_3):724 return fixt_3 * 3725 @lcc.fixture(names=["fixt_1"], scope="test")726 def fixt1(fixt_2):727 return fixt_2 * 4728 @lcc.suite("MySuite")729 class MySuite:730 @lcc.test("Test")731 def test(self, fixt_1):732 marker.append(fixt_1)733 run_suite_class(MySuite, fixtures=[fixt1, fixt2, fixt3])734 assert marker == [24]735def test_run_with_suite_fixture_used_in_subsuite():736 marker = []737 @lcc.fixture(scope="suite")738 def fixt1():739 yield 1740 marker.append(2)741 @lcc.suite("MySuiteA")742 class MySuiteA:743 @lcc.test("Test")744 def test(self, fixt1):745 marker.append(fixt1)746 @lcc.suite("MySuiteB")747 class MySuiteB:748 @lcc.test("Test")749 def test(self, fixt1):750 marker.append(fixt1)751 @lcc.suite("MySuiteC")752 class MySuiteC:753 @lcc.test("Test")754 def test(self, fixt1):755 marker.append(fixt1)756 run_suite_class(MySuiteA, fixtures=[fixt1])757 assert marker == [1, 2, 1, 2, 1, 2]758def test_run_with_fixture_used_in_setup_suite():759 marker = []760 @lcc.fixture(scope="suite")761 def fixt1():762 return 1763 @lcc.suite("MySuiteA")764 class MySuite:765 def setup_suite(self, fixt1):766 marker.append(fixt1)767 @lcc.test("sometest")768 def sometest(self):769 pass770 run_suite_class(MySuite, fixtures=[fixt1])771 assert marker == [1]772def test_run_with_fixture_injected_in_class():773 marker = []774 @lcc.fixture(scope="session")775 def fixt1():776 return 1777 @lcc.suite("MySuiteA")778 class MySuite:779 fixt1 = lcc.inject_fixture()780 @lcc.test("sometest")781 def sometest(self):782 marker.append(self.fixt1)783 report = run_suite_class(MySuite, fixtures=[fixt1])784 assert_test_passed(report)785 assert marker == [1]786def test_run_with_fixture_injected_in_class_and_fixture_name_arg():787 marker = []788 @lcc.fixture(scope="session")789 def fixt1():790 return 1791 @lcc.suite("MySuiteA")792 class MySuite:793 fxt = lcc.inject_fixture("fixt1")794 @lcc.test("sometest")795 def sometest(self):796 marker.append(self.fxt)797 report = run_suite_class(MySuite, fixtures=[fixt1])798 assert_test_passed(report)799 assert marker == [1]800def test_run_with_fixture_injected_in_module():801 @lcc.fixture(scope="suite")802 def fixt1():803 return "MARKER"804 suite = build_suite_from_module("""805fixt1 = lcc.inject_fixture()806@lcc.test("Some test")807def sometest():808 lcc.log_info(fixt1)809 """)810 report = run_suite(suite, fixtures=[fixt1])811 test = next(report.all_tests())812 assert test.get_steps()[0].get_logs()[0].message == "MARKER"813def test_run_with_fixture_per_thread():814 @lcc.fixture(scope="session", per_thread=True)815 def fixt():816 return object()817 witness = defaultdict(set)818 @lcc.suite()819 class Suite:820 @lcc.test()821 @lcc.parametrized({"value": value} for value in range(20)) # create 20 different tests822 def test(self, value, fixt):823 time.sleep(0.01) # make sure that each thread will be able to execute some tests824 witness[threading.current_thread().ident].add(fixt)825 run_suite_class(Suite, fixtures=(fixt,), nb_threads=4)826 # make sure that for each test-thread, the same fixture actual value is returned:827 assert len(witness) >= 1828 for objects in witness.values():829 assert len(objects) == 1830def test_run_with_fixture_per_thread_logging():831 @lcc.fixture(scope="session", per_thread=True)832 def fixt():833 lcc.log_info("Fixture setup")834 yield 1835 lcc.log_info("Fixture teardown")836 @lcc.suite()837 class Suite:838 @lcc.test()839 def test(self, fixt):840 pass841 report = run_suite_class(Suite, fixtures=(fixt,))842 test = get_last_test(report)843 assert test.get_steps()[0].get_logs()[0].message == "Fixture setup"844 assert report.test_session_teardown.get_steps()[0].get_logs()[0].message == "Fixture teardown"845def test_fixture_called_multiple_times():846 marker = []847 @lcc.fixture(scope="test")848 def fixt():849 return 1850 @lcc.suite("MySuite")851 class MySuite:852 @lcc.test("test 1")853 def test_1(self, fixt):854 marker.append(fixt)855 @lcc.test("test 2")856 def test_2(self, fixt):857 marker.append(fixt)858 run_suite_class(MySuite, fixtures=[fixt])859 assert marker == [1, 1]860def test_fixture_name_scopes():861 fixts = []862 @lcc.fixture(scope="session")863 def fixt_pre_run(fixture_name):864 fixts.append(fixture_name)865 @lcc.fixture(scope="session")866 def fixt_session(fixture_name, fixt_pre_run):867 fixts.append(fixture_name)868 @lcc.fixture(scope="suite")869 def fixt_suite(fixture_name, fixt_session):870 fixts.append(fixture_name)871 @lcc.fixture(scope="test")872 def fixt_test(fixture_name, fixt_suite):873 fixts.append(fixture_name)874 @lcc.suite("suite")875 class suite:876 @lcc.test("test")877 def test(self, fixt_test):878 pass879 run_suite_class(suite, fixtures=[fixt_pre_run, fixt_session, fixt_suite, fixt_test])880 assert fixts == ["fixt_pre_run", "fixt_session", "fixt_suite", "fixt_test"]881def test_fixture_name_multiple_names():882 fixts = []883 @lcc.fixture(scope="test", names=["fixt1", "fixt2"])884 def fixt(fixture_name):885 fixts.append(fixture_name)886 @lcc.suite("suite")887 class suite:888 @lcc.test("test")889 def test(self, fixt1, fixt2):890 pass891 run_suite_class(suite, fixtures=[fixt])892 assert sorted(fixts) == ["fixt1", "fixt2"]893def test_fixture_with_test_scope_on_disabled_test():894 marker = []895 @lcc.fixture(scope="test")896 def fixt():897 marker.append("i've been executed")898 @lcc.suite("suite")899 class suite:900 @lcc.test("test 1")901 @lcc.disabled()902 def test_1(self, fixt):903 pass904 @lcc.test("test 2")905 def test_2(self):906 pass907 report = run_suite_class(suite, fixtures=[fixt])908 assert_test_statuses(report, disabled=["suite.test_1"], passed=["suite.test_2"])909 assert not marker910def test_fixture_with_suite_scope_on_disabled_test():911 marker = []912 @lcc.fixture(scope="suite")913 def fixt():914 marker.append("i've been executed")915 @lcc.suite("suite")916 class suite:917 @lcc.test("test 1")918 @lcc.disabled()919 def test_1(self, fixt):920 pass921 @lcc.test("test 2")922 def test_2(self):923 pass924 report = run_suite_class(suite, fixtures=[fixt])925 assert_test_statuses(report, disabled=["suite.test_1"], passed=["suite.test_2"])926 assert not marker927def test_fixture_with_suite_scope_on_disabled_test_and_force_disabled():928 marker = []929 @lcc.fixture(scope="suite")930 def fixt():931 marker.append("i've been executed")932 @lcc.suite("suite")933 class suite:934 @lcc.test("test 1")935 @lcc.disabled()936 def test_1(self, fixt):937 pass938 @lcc.test("test 2")939 def test_2(self):940 pass941 report = run_suite_class(suite, fixtures=[fixt], force_disabled=True)942 assert_test_statuses(report, passed=["suite.test_1", "suite.test_2"])943 assert marker944def test_fixture_with_session_scope_on_disabled_test():945 marker = []946 @lcc.fixture(scope="session")947 def fixt():948 marker.append("i've been executed")949 @lcc.suite("suite")950 class suite:951 @lcc.test("test 1")952 @lcc.disabled()953 def test_1(self, fixt):954 pass955 @lcc.test("test 2")956 def test_2(self):957 pass958 report = run_suite_class(suite, fixtures=[fixt])959 assert_test_statuses(report, disabled=["suite.test_1"], passed=["suite.test_2"])960 assert not marker961def test_fixture_with_session_scope_on_disabled_test_and_force_disabled():962 marker = []963 @lcc.fixture(scope="session")964 def fixt():965 marker.append("i've been executed")966 @lcc.suite("suite")967 class suite:968 @lcc.test("test 1")969 @lcc.disabled()970 def test_1(self, fixt):971 pass972 @lcc.test("test 2")973 def test_2(self):974 pass975 report = run_suite_class(suite, fixtures=[fixt], force_disabled=True)976 assert_test_statuses(report, passed=["suite.test_1", "suite.test_2"])977 assert marker978def test_fixture_with_pre_run_scope_on_disabled_test():979 marker = []980 @lcc.fixture(scope="pre_run")981 def fixt():982 marker.append("i've been executed")983 @lcc.suite("suite")984 class suite:985 @lcc.test("test 1")986 @lcc.disabled()987 def test_1(self, fixt):988 pass989 @lcc.test("test 2")990 def test_2(self):991 pass992 report = run_suite_class(suite, fixtures=[fixt])993 assert_test_statuses(report, disabled=["suite.test_1"], passed=["suite.test_2"])994 assert not marker995def test_fixture_with_pre_run_scope_on_disabled_test_and_force_disabled():996 marker = []997 @lcc.fixture(scope="pre_run")998 def fixt():999 marker.append("i've been executed")1000 @lcc.suite("suite")1001 class suite:1002 @lcc.test("test 1")1003 @lcc.disabled()1004 def test_1(self, fixt):1005 pass1006 @lcc.test("test 2")1007 def test_2(self):1008 pass1009 report = run_suite_class(suite, fixtures=[fixt], force_disabled=True)1010 assert_test_statuses(report, passed=["suite.test_1", "suite.test_2"])1011 assert marker1012def test_fixture_in_suite_with_disabled_test():1013 marker = []1014 @lcc.fixture(scope="suite")1015 def fixt():1016 marker.append("i've been executed")1017 @lcc.suite("suite_1")1018 class suite_1:1019 fixt = lcc.inject_fixture()1020 @lcc.test("test")1021 @lcc.disabled()1022 def test(self, fixt):1023 pass1024 @lcc.suite("suite_2")1025 class suite_2:1026 @lcc.test("test")1027 def test(self):1028 pass1029 report = run_suite_classes((suite_1, suite_2), fixtures=[fixt])1030 assert_test_statuses(report, disabled=["suite_1.test"], passed=["suite_2.test"])1031 assert not marker1032def test_fixture_in_suite_with_disabled_test_and_force_disabled():1033 marker = []1034 @lcc.fixture(scope="suite")1035 def fixt():1036 marker.append("i've been executed")1037 @lcc.suite("suite_1")1038 class suite_1:1039 fixt = lcc.inject_fixture()1040 @lcc.test("test")1041 @lcc.disabled()1042 def test(self, fixt):1043 pass1044 @lcc.suite("suite_2")1045 class suite_2:1046 @lcc.test("test")1047 def test(self):1048 pass1049 report = run_suite_classes((suite_1, suite_2), fixtures=[fixt], force_disabled=True)1050 assert_test_statuses(report, passed=["suite_1.test", "suite_2.test"])1051 assert marker1052def test_fixture_evaluation_order():1053 @lcc.fixture()1054 def a():1055 lcc.log_info("a")1056 @lcc.fixture()1057 def b():1058 lcc.log_info("b")1059 @lcc.fixture()1060 def c(b):1061 lcc.log_info("c")1062 @lcc.suite()1063 class suite:1064 @lcc.test()1065 def test(self, a, c):1066 pass1067 report = run_suite_class(suite, fixtures=(a, b, c))1068 test = get_last_test(report)1069 assert [e.message for e in test.get_steps()[0].get_logs()] == ["a", "b", "c"]1070def test_parametrized_simple():1071 @lcc.suite("suite")1072 class suite:1073 @lcc.test("test")1074 @lcc.parametrized([{"value": "foo"}])1075 def test(self, value):1076 lcc.log_info(value)1077 report = run_suite_class(suite)1078 test = get_last_test(report)1079 assert test.name == "test_1"1080 assert test.description == "test #1"1081 log = get_last_log(report)1082 assert log.message == "foo"1083def test_parametrized_with_multiple_test_and_fixture():1084 @lcc.fixture(scope="session")1085 def fixt():1086 return "something"1087 @lcc.suite("suite")1088 class suite:1089 @lcc.test("test")1090 @lcc.parametrized([{"value_1": "foo", "value_2": "bar"}, {"value_1": "baz", "value_2": "foo"}])1091 def test(self, value_1, value_2, fixt):1092 lcc.log_info(value_1)1093 lcc.log_info(value_2)1094 lcc.log_info(fixt)1095 report = run_suite_class(suite, fixtures=[fixt])1096 test_1, test_2 = report.all_tests()1097 assert test_1.name == "test_1"1098 assert test_1.description == "test #1"1099 assert test_1.get_steps()[0].get_logs()[0].message == "foo"1100 assert test_1.get_steps()[0].get_logs()[1].message == "bar"1101 assert test_1.get_steps()[0].get_logs()[2].message == "something"1102 assert test_2.name == "test_2"1103 assert test_2.description == "test #2"1104 assert test_2.get_steps()[0].get_logs()[0].message == "baz"1105 assert test_2.get_steps()[0].get_logs()[1].message == "foo"1106 assert test_2.get_steps()[0].get_logs()[2].message == "something"1107def test_parametrized_extra_param():1108 @lcc.suite("suite")1109 class suite:1110 @lcc.test("test")1111 @lcc.parametrized([{"value": "foo", "extra": "bar"}])1112 def test(self, value):1113 lcc.log_info(value)1114 report = run_suite_class(suite)1115 test = get_last_test(report)1116 assert test.name == "test_1"1117 assert test.description == "test #1"1118 log = get_last_log(report)1119 assert log.message == "foo"1120def test_stop_on_failure_test():1121 @lcc.suite("Suite")1122 class suite:1123 @lcc.test("Test 1")1124 def test1(self):1125 1 / 01126 1127 @lcc.test("Test 2")1128 def test2(self):1129 pass1130 report = run_suite_class(suite, stop_on_failure=True)1131 assert_test_statuses(report, failed=["suite.test1"], skipped=["suite.test2"])1132def test_stop_on_failure_suite_setup():1133 @lcc.suite("Suite 1")1134 class suite1:1135 def setup_suite(self):1136 1 / 01137 1138 @lcc.test("Test 1")1139 def test1(self):1140 pass1141 1142 @lcc.suite("Suite 2")1143 class suite2:1144 @lcc.test("Test 2")1145 def test2(self):1146 pass1147 report = run_suite_classes([suite1, suite2], stop_on_failure=True)1148 assert_test_statuses(report, skipped=["suite1.test1", "suite2.test2"])1149def test_stop_on_failure_suite_teardown():1150 @lcc.suite("Suite 1")1151 class suite1:1152 @lcc.test("Test 1")1153 def test1(self):1154 pass1155 def teardown_suite(self):1156 1 / 01157 1158 @lcc.suite("Suite 2")1159 class suite2:1160 @lcc.test("Test 2")1161 def test2(self):1162 pass1163 report = run_suite_classes([suite1, suite2], stop_on_failure=True)1164 assert_test_statuses(report, passed=["suite1.test1"], skipped=["suite2.test2"])1165def test_disabled_test():1166 @lcc.suite("Suite")1167 class mysuite:1168 @lcc.test("Test")1169 @lcc.disabled()1170 def mytest(self):1171 pass1172 report = run_suite_class(mysuite)1173 assert_test_statuses(report, disabled=["mysuite.mytest"])1174def test_disabled_test_with_reason():1175 @lcc.suite("Suite")1176 class mysuite:1177 @lcc.test("Test")1178 @lcc.disabled("some reason")1179 def mytest(self):1180 pass1181 report = run_suite_class(mysuite)1182 test = get_last_test(report)1183 assert test.status == "disabled"1184 assert test.status_details == "some reason"1185def test_disabled_test_with_force_disabled():1186 @lcc.suite("Suite")1187 class mysuite:1188 @lcc.test("Test")1189 @lcc.disabled()1190 def mytest(self):1191 pass1192 report = run_suite_class(mysuite, force_disabled=True)1193 assert_test_statuses(report, passed=["mysuite.mytest"])1194def test_disabled_suite():1195 @lcc.suite("Suite")1196 @lcc.disabled()1197 class mysuite:1198 @lcc.test("Test 1")1199 def test1(self):1200 pass1201 @lcc.test("Test 2")1202 def test2(self):1203 pass1204 report = run_suite_class(mysuite)1205 assert_test_statuses(report, disabled=["mysuite.test1", "mysuite.test2"])1206def test_disabled_suite_with_reason():1207 @lcc.suite("Suite")1208 @lcc.disabled("some reason")1209 class mysuite:1210 @lcc.test("Test 1")1211 def test1(self):1212 pass1213 @lcc.test("Test 2")1214 def test2(self):1215 pass1216 report = run_suite_class(mysuite)1217 test_1, test_2 = list(report.all_tests())1218 assert test_1.status == test_2.status == "disabled"1219 assert test_1.status_details == test_2.status_details == "some reason"1220def test_disabled_in_skipped_suite():1221 @lcc.suite("Suite")1222 class mysuite:1223 def setup_suite(self):1224 lcc.log_error("something wrong happened")1225 @lcc.test("Test 1")1226 def test1(self):1227 pass1228 @lcc.test("Test 2")1229 @lcc.disabled()1230 def test2(self):1231 pass1232 report = run_suite_class(mysuite)1233 assert_test_statuses(report, skipped=["mysuite.test1"], disabled=["mysuite.test2"])1234def test_get_fixture():1235 marker = []1236 @lcc.fixture(scope="pre_run")1237 def fixt():1238 return 421239 @lcc.suite("mysuite")1240 class mysuite:1241 @lcc.test("mytest")1242 def mytest(self, fixt):1243 marker.append(lcc.get_fixture("fixt"))1244 run_suite_class(mysuite, fixtures=[fixt])1245 assert marker == [42]1246def test_get_fixture_bad_scope():1247 marker = []1248 @lcc.fixture(scope="test")1249 def fixt():1250 return 421251 @lcc.suite("mysuite")1252 class mysuite:1253 @lcc.test("mytest")1254 def mytest(self, fixt):1255 try:1256 lcc.get_fixture("fixt")1257 except LookupError:1258 marker.append("exception")1259 run_suite_class(mysuite, fixtures=[fixt])1260 assert marker == ["exception"]1261def test_get_fixture_unknown():1262 marker = []1263 @lcc.suite("mysuite")1264 class mysuite:1265 @lcc.test("mytest")1266 def mytest(self):1267 try:1268 lcc.get_fixture("fixt")1269 except LookupError:1270 marker.append("exception")1271 run_suite_class(mysuite)1272 assert marker == ["exception"]1273def test_get_fixture_not_executed():1274 marker = []1275 @lcc.fixture(scope="pre_run")1276 def fixt():1277 return 421278 @lcc.suite("mysuite")1279 class mysuite:1280 @lcc.test("mytest")1281 def mytest(self):1282 try:1283 lcc.get_fixture("fixt")1284 except LookupError:1285 marker.append("exception")1286 run_suite_class(mysuite)1287 assert marker == ["exception"]1288def test_exception_in_reporting_backend(tmpdir):1289 class MyException(Exception):1290 pass1291 class MyReportingSession(ReportingSession):1292 def on_log(self, event):1293 raise MyException()1294 class MyReportingBackend(ReportingBackend):1295 def create_reporting_session(self, report_dir, report, parallel, saving_strategy):1296 return MyReportingSession()1297 @lcc.suite("MySuite")1298 class mysuite(object):1299 @lcc.test("mytest")1300 def mytest(self):1301 lcc.log_info("some log")1302 with pytest.raises(MyException) as excinfo:1303 run_suite_class(mysuite, backends=[MyReportingBackend()], tmpdir=tmpdir)1304# this bug was provoke a freeze and was introduced in 0.21.0 and fixed in 0.22.31305def test_bug_in_task_handling():1306 @lcc.suite("suite")1307 class suite:1308 @lcc.test("test 1")1309 def test_1(self):1310 lcc.log_error("error")1311 @lcc.test("test 2")1312 def test_2(self):1313 lcc.log_error("error")1314 @lcc.test("test 3")1315 def test_3(self):1316 pass1317 report = run_suite_class(suite)1318 assert_test_statuses(report, failed=["suite.test_1", "suite.test_2"], passed=["suite.test_3"])1319def test_depends_on_passed():1320 @lcc.suite("s")1321 class suite:1322 @lcc.test("t1")1323 def test1(self):1324 pass1325 @lcc.test("t2")1326 @lcc.depends_on("suite.test1")1327 def test2(self):1328 pass1329 report = run_suite_class(suite)1330 assert_test_statuses(report, passed=["suite.test1", "suite.test2"])1331def test_depends_on_failed_exception():1332 @lcc.suite("s")1333 class suite:1334 @lcc.test("t1")1335 def test1(self):1336 raise Exception()1337 @lcc.test("t2")1338 @lcc.depends_on("suite.test1")1339 def test2(self):1340 pass1341 @lcc.test("t3")1342 def test3(self):1343 pass1344 report = run_suite_class(suite)1345 assert_test_statuses(report, failed=["suite.test1"], skipped=["suite.test2"], passed=["suite.test3"])1346def test_depends_on_failed_failure():1347 @lcc.suite("s")1348 class suite:1349 @lcc.test("t1")1350 def test1(self):1351 lcc.log_error("some error")1352 @lcc.test("t2")1353 @lcc.depends_on("suite.test1")1354 def test2(self):1355 pass1356 @lcc.test("t3")1357 def test3(self):1358 pass1359 report = run_suite_class(suite)1360 assert_test_statuses(report, failed=["suite.test1"], skipped=["suite.test2"], passed=["suite.test3"])1361def test_depends_on_skipped():1362 @lcc.suite("s")1363 class suite:1364 @lcc.test("t1")1365 def test1(self):1366 lcc.log_error("some error")1367 @lcc.test("t2")1368 @lcc.depends_on("suite.test1")1369 def test2(self):1370 pass1371 @lcc.test("t3")1372 @lcc.depends_on("suite.test2")1373 def test3(self):1374 pass1375 report = run_suite_class(suite)1376 assert_test_statuses(report, failed=["suite.test1"], skipped=["suite.test2", "suite.test3"])1377def test_depends_on_failed_and_subsuite():1378 @lcc.suite("s1")1379 class suite1:1380 @lcc.test("t1")1381 def test1(self):1382 lcc.log_error("some error")1383 @lcc.suite("s2")1384 class suite2:1385 @lcc.test("t2")1386 @lcc.depends_on("suite1.test1")1387 def test2(self):1388 pass1389 report = run_suite_class(suite1)...

Full Screen

Full Screen

test_report_writer.py

Source:test_report_writer.py Github

copy

Full Screen

...36 class mysuite:37 @lcc.test("Some test")38 def sometest(self):39 pass40 report = run_suite_class(mysuite)41 assert_report_from_suite(report, mysuite)42def test_test_with_all_metadata():43 @lcc.suite("MySuite")44 class mysuite:45 @lcc.link("http://foo.bar", "foobar")46 @lcc.prop("foo", "bar")47 @lcc.tags("foo", "bar")48 @lcc.test("Some test")49 def sometest(self):50 pass51 report = run_suite_class(mysuite)52 assert_report_from_suite(report, mysuite)53def test_suite_with_all_metadata():54 @lcc.link("http://foo.bar", "foobar")55 @lcc.prop("foo", "bar")56 @lcc.tags("foo", "bar")57 @lcc.suite("MySuite")58 class mysuite:59 @lcc.test("Some test")60 def sometest(self):61 pass62 report = run_suite_class(mysuite)63 assert_report_from_suite(report, mysuite)64def test_multiple_suites_and_tests():65 @lcc.suite("MySuite1")66 class mysuite1:67 @lcc.tags("foo")68 @lcc.test("Some test 1")69 def test_1_1(self):70 pass71 @lcc.tags("bar")72 @lcc.test("Some test 2")73 def test_1_2(self):74 pass75 @lcc.tags("baz")76 @lcc.test("Some test 3")77 def test_1_3(self):78 pass79 @lcc.suite("MySuite2")80 class mysuite2:81 @lcc.prop("foo", "bar")82 @lcc.test("Some test 1")83 def test_2_1(self):84 pass85 @lcc.prop("foo", "baz")86 @lcc.test("Some test 2")87 def test_2_2(self):88 pass89 @lcc.test("Some test 3")90 def test_2_3(self):91 pass92 # suite3 is a sub suite of suite293 @lcc.suite("MySuite3")94 class mysuite3:95 @lcc.prop("foo", "bar")96 @lcc.test("Some test 1")97 def test_3_1(self):98 pass99 @lcc.prop("foo", "baz")100 @lcc.test("Some test 2")101 def test_3_2(self):102 pass103 @lcc.test("Some test 3")104 def test_3_3(self):105 pass106 report = run_suite_classes([mysuite1, mysuite2])107 assert_report_from_suites(report, [mysuite1, mysuite2])108def test_check_success():109 @lcc.suite("MySuite")110 class mysuite:111 @lcc.test("Test 1")112 def test_1(self):113 check_that("somevalue", "foo", equal_to("foo"))114 report = run_suite_class(mysuite)115 test = get_last_test(report)116 assert test.status == "passed"117 step = test.get_steps()[0]118 assert "somevalue" in step.get_logs()[0].description119 assert "foo" in step.get_logs()[0].description120 assert step.get_logs()[0].is_successful is True121 assert "foo" in step.get_logs()[0].details122def test_check_failure():123 @lcc.suite("MySuite")124 class mysuite:125 @lcc.test("Test 1")126 def test_1(self):127 check_that("somevalue", "foo", equal_to("bar"))128 report = run_suite_class(mysuite)129 test = get_last_test(report)130 assert test.status == "failed"131 step = test.get_steps()[0]132 assert "somevalue" in step.get_logs()[0].description133 assert "bar" in step.get_logs()[0].description134 assert step.get_logs()[0].is_successful is False135 assert "foo" in step.get_logs()[0].details136def test_require_success():137 @lcc.suite("MySuite")138 class mysuite:139 @lcc.test("Test 1")140 def test_1(self):141 require_that("somevalue", "foo", equal_to("foo"))142 report = run_suite_class(mysuite)143 test = get_last_test(report)144 assert test.status == "passed"145 step = test.get_steps()[0]146 assert "somevalue" in step.get_logs()[0].description147 assert "foo" in step.get_logs()[0].description148 assert step.get_logs()[0].is_successful is True149 assert "foo" in step.get_logs()[0].details150def test_require_failure():151 @lcc.suite("MySuite")152 class mysuite:153 @lcc.test("Test 1")154 def test_1(self):155 require_that("somevalue", "foo", equal_to("bar"))156 report = run_suite_class(mysuite)157 test = get_last_test(report)158 assert test.status == "failed"159 step = test.get_steps()[0]160 assert "somevalue" in step.get_logs()[0].description161 assert "bar" in step.get_logs()[0].description162 assert step.get_logs()[0].is_successful is False163 assert "foo" in step.get_logs()[0].details164def test_all_types_of_logs():165 @lcc.suite("MySuite")166 class mysuite:167 @lcc.test("Test 1")168 def test_1(self):169 lcc.log_debug("some debug message")170 lcc.log_info("some info message")171 lcc.log_warning("some warning message")172 @lcc.test("Test 2")173 def test_2(self):174 lcc.log_error("some error message")175 report = run_suite_class(mysuite)176 test = report.get_test("mysuite.test_1")177 assert test.status == "passed"178 step = test.get_steps()[0]179 assert step.get_logs()[0].level == "debug"180 assert step.get_logs()[0].message == "some debug message"181 assert step.get_logs()[1].level == "info"182 assert step.get_logs()[1].message == "some info message"183 assert step.get_logs()[2].level == "warn"184 test = report.get_test("mysuite.test_2")185 assert test.status == "failed"186 step = test.get_steps()[0]187 assert step.get_logs()[0].message == "some error message"188 assert step.get_logs()[0].level == "error"189def test_multiple_steps():190 @lcc.suite("MySuite")191 class mysuite:192 @lcc.test("Some test")193 def sometest(self):194 lcc.set_step("step 1")195 lcc.log_info("do something")196 lcc.set_step("step 2")197 lcc.log_info("do something else")198 report = run_suite_class(mysuite)199 test = get_last_test(report)200 assert test.status == "passed"201 steps = test.get_steps()202 assert steps[0].description == "step 1"203 assert steps[0].get_logs()[0].level == "info"204 assert steps[0].get_logs()[0].message == "do something"205 assert steps[1].description == "step 2"206 assert steps[1].get_logs()[0].level == "info"207 assert steps[1].get_logs()[0].message == "do something else"208def test_multiple_steps_on_different_threads():209 def thread_func(i):210 lcc.set_step(str(i))211 time.sleep(0.001)212 lcc.log_info(str(i))213 @lcc.suite("MySuite")214 class mysuite:215 @lcc.test("Some test")216 def sometest(self):217 threads = [lcc.Thread(target=thread_func, args=(i,)) for i in range(3)]218 for thread in threads:219 thread.start()220 for thread in threads:221 thread.join()222 report = run_suite_class(mysuite)223 test = get_last_test(report)224 remainings = list(range(3))225 steps = test.get_steps()226 for step in steps:227 remainings.remove(int(step.description))228 assert len(step.get_logs()) == 1229 assert step.get_logs()[0].message == step.description230 assert len(remainings) == 0231def test_thread_logging_without_explicit_step():232 @lcc.suite("MySuite")233 class mysuite:234 @lcc.test("Some test")235 def sometest(self):236 thread = lcc.Thread(target=lambda: lcc.log_info("doing something"))237 thread.start()238 thread.join()239 report = run_suite_class(mysuite)240 test = get_last_test(report)241 assert test.status == "passed"242 assert len(test.get_steps()) == 1243 step = test.get_steps()[0]244 assert step.description == "Some test"245 assert step.get_logs()[0].level == "info"246 assert "doing something" == step.get_logs()[0].message247def test_thread_logging_without_detached_bis():248 def func():249 lcc.log_info("log in thread")250 @lcc.suite("MySuite")251 class mysuite:252 @lcc.test("Some test")253 def sometest(self):254 lcc.set_step("Step 1")255 lcc.log_info("log 1")256 thread = lcc.Thread(target=func)257 lcc.set_step("Step 2")258 lcc.log_info("log 2")259 thread.start()260 thread.join()261 report = run_suite_class(mysuite)262 test = get_last_test(report)263 assert test.status == "passed"264 steps = test.get_steps()265 assert len(steps) == 3266 step = test.get_steps()[0]267 assert step.description == "Step 1"268 assert step.get_logs()[0].message == "log 1"269 step = test.get_steps()[1]270 assert step.description == "Step 2"271 assert step.get_logs()[0].message == "log 2"272 step = test.get_steps()[2]273 assert step.description == "Step 1"274 assert step.get_logs()[0].message == "log in thread"275def test_exception_in_thread():276 def thread_func():277 lcc.log_info("doing something")278 raise Exception("this_is_an_exception")279 @lcc.suite("MySuite")280 class mysuite:281 @lcc.test("Some test")282 def sometest(self):283 thread = lcc.Thread(target=thread_func)284 thread.start()285 thread.join()286 report = run_suite_class(mysuite)287 test = get_last_test(report)288 assert test.status == "failed"289 steps = test.get_steps()290 assert len(steps) == 1291 step = steps[0]292 assert step.description == "Some test"293 assert step.get_logs()[-1].level == "error"294 assert "this_is_an_exception" in step.get_logs()[-1].message295def test_same_step_in_two_threads():296 def thread_func():297 lcc.set_step("step 2")298 lcc.log_info("log 2")299 time.sleep(0.001)300 lcc.set_step("step 1")301 lcc.log_info("log 3")302 @lcc.suite("MySuite")303 class mysuite:304 @lcc.test("Some test")305 def sometest(self):306 lcc.set_step("step 1")307 lcc.log_info("log 1")308 thread = lcc.Thread(target=thread_func)309 thread.start()310 lcc.log_info("log 4")311 thread.join()312 report = run_suite_class(mysuite)313 test = get_last_test(report)314 steps = test.get_steps()315 assert len(steps) == 3316 step = steps[0]317 assert step.description == "step 1"318 assert len(step.get_logs()) == 2319 assert step.get_logs()[0].message == "log 1"320 assert step.get_logs()[1].message == "log 4"321 step = steps[1]322 assert step.description == "step 2"323 assert len(step.get_logs()) == 1324 assert step.get_logs()[0].message == "log 2"325 step = steps[2]326 assert step.description == "step 1"327 assert len(step.get_logs()) == 1328 assert step.get_logs()[0].message == "log 3"329def test_deprecated_end_step():330 @lcc.suite("MySuite")331 class mysuite:332 @lcc.test("Some test")333 def sometest(self):334 lcc.set_step("step")335 lcc.log_info("log")336 lcc.end_step("step")337 with pytest.warns(DeprecationWarning, match="deprecated"):338 report = run_suite_class(mysuite)339 test = get_last_test(report)340 assert test.status == "passed"341 step = test.get_steps()[0]342 assert step.description == "step"343 assert step.get_logs()[0].level == "info"344 assert step.get_logs()[0].message == "log"345def test_deprecated_detached_step():346 @lcc.suite("MySuite")347 class mysuite:348 @lcc.test("Some test")349 def sometest(self):350 with lcc.detached_step("step"):351 lcc.log_info("log")352 with pytest.warns(DeprecationWarning, match="deprecated"):353 report = run_suite_class(mysuite)354 test = get_last_test(report)355 step = test.get_steps()[0]356 assert test.status == "passed"357 assert step.description == "step"358 assert step.get_logs()[0].level == "info"359 assert step.get_logs()[0].message == "log"360def test_default_step():361 @lcc.suite("MySuite")362 class mysuite:363 @lcc.test("Some test")364 def sometest(self):365 lcc.log_info("do something")366 report = run_suite_class(mysuite)367 test = get_last_test(report)368 assert test.status == "passed"369 step = test.get_steps()[0]370 assert step.description == "Some test"371 assert step.get_logs()[0].level == "info"372 assert step.get_logs()[0].message == "do something"373def test_step_after_test_setup():374 @lcc.suite("mysuite")375 class mysuite:376 def setup_test(self, test):377 lcc.log_info("in test setup")378 @lcc.test("Some test")379 def sometest(self):380 lcc.log_info("do something")381 report = run_suite_class(mysuite)382 test = get_last_test(report)383 assert test.status == "passed"384 steps = test.get_steps()385 assert steps[0].description == "Setup test"386 assert steps[0].get_logs()[0].level == "info"387 assert steps[0].get_logs()[0].message == "in test setup"388 assert steps[1].description == "Some test"389 assert steps[1].get_logs()[0].level == "info"390 assert steps[1].get_logs()[0].message == "do something"391def test_prepare_attachment(tmpdir):392 def do():393 with lcc.prepare_attachment("foobar.txt", "some description") as filename:394 with open(filename, "w") as fh:395 fh.write("some content")396 report = run_func_in_test(do, tmpdir=tmpdir)397 assert_attachment(398 get_last_attachment(report), "foobar.txt", "some description", False, "some content", make_file_reader()399 )400def test_prepare_image_attachment(tmpdir):401 def do():402 with lcc.prepare_image_attachment("foobar.png", "some description") as filename:403 with open(filename, "wb") as fh:404 fh.write(SAMPLE_IMAGE_CONTENT)405 report = run_func_in_test(do, tmpdir=tmpdir)406 assert_attachment(407 get_last_attachment(report), "foobar.png", "some description", True, SAMPLE_IMAGE_CONTENT,408 make_file_reader(binary=True)409 )410def test_save_attachment_file(tmpdir):411 def do():412 filename = osp.join(tmpdir.strpath, "somefile.txt")413 with open(filename, "w") as fh:414 fh.write("some other content")415 lcc.save_attachment_file(filename, "some other file")416 report = run_func_in_test(do, tmpdir=tmpdir.mkdir("report"))417 assert_attachment(418 get_last_attachment(report), "somefile.txt", "some other file", False, "some other content", make_file_reader()419 )420def test_save_image_file(tmpdir):421 def do():422 lcc.save_image_file(SAMPLE_IMAGE_PATH, "some other file")423 report = run_func_in_test(do, tmpdir=tmpdir.mkdir("report"))424 assert_attachment(425 get_last_attachment(report), osp.basename(SAMPLE_IMAGE_PATH), "some other file", True, SAMPLE_IMAGE_CONTENT,426 make_file_reader(binary=True)427 )428def _test_save_attachment_content(tmpdir, file_name, file_content, file_reader):429 def do():430 lcc.save_attachment_content(file_content, file_name)431 report = run_func_in_test(do, tmpdir=tmpdir)432 assert_attachment(get_last_attachment(report), file_name, file_name, False, file_content, file_reader)433def test_save_attachment_text_ascii(tmpdir):434 _test_save_attachment_content(tmpdir, "foobar.txt", "foobar", make_file_reader())435def test_save_attachment_text_utf8(tmpdir):436 _test_save_attachment_content(tmpdir, "foobar.txt", u"éééçççààà", make_file_reader(encoding="utf-8"))437def test_save_attachment_binary(tmpdir):438 _test_save_attachment_content(tmpdir, "foobar.png", SAMPLE_IMAGE_CONTENT, make_file_reader(binary=True))439def test_save_image_content(tmpdir):440 def do():441 lcc.save_image_content(SAMPLE_IMAGE_CONTENT, "somefile.png", "some file")442 report = run_func_in_test(do, tmpdir=tmpdir)443 assert_attachment(444 get_last_attachment(report), "somefile.png", "some file", True, SAMPLE_IMAGE_CONTENT,445 make_file_reader(binary=True)446 )447def test_log_url():448 @lcc.suite("MySuite")449 class mysuite:450 @lcc.test("Some test")451 def sometest(self):452 lcc.log_url("http://example.com", "example")453 report = run_suite_class(mysuite)454 test = get_last_test(report)455 step = test.get_steps()[0]456 assert step.get_logs()[0].description == "example"457 assert step.get_logs()[0].url == "http://example.com"458def test_unicode(tmpdir):459 @lcc.suite("MySuite")460 class mysuite:461 @lcc.test("some test")462 def sometest(self):463 lcc.set_step(u"éééààà")464 check_that(u"éééààà", 1, equal_to(1))465 lcc.log_info(u"éééààà")466 lcc.save_attachment_content("A" * 1024, u"somefileààà", u"éééààà")467 report = run_suite_class(mysuite, tmpdir=tmpdir)468 test = get_last_test(report)469 assert test.status == "passed"470 step = test.get_steps()[0]471 assert step.description == u"éééààà"472 assert u"éééààà" in step.get_logs()[0].description473 assert "1" in step.get_logs()[0].description474 assert step.get_logs()[1].message == u"éééààà"475 assert_attachment(step.get_logs()[2], u"somefileààà", u"éééààà", False, "A" * 1024, make_file_reader(encoding="utf8"))476def test_setup_suite_success():477 @lcc.suite("MySuite")478 class mysuite:479 def setup_suite(self):480 lcc.log_info("some log")481 @lcc.test("Some test")482 def sometest(self):483 pass484 report = run_suite_class(mysuite)485 setup = _get_suite_setup(report)486 assert setup.status == "passed"487 assert setup.start_time is not None488 assert setup.end_time is not None489 assert setup.get_steps()[0].get_logs()[0].message == "some log"490 assert setup.is_successful()491def test_setup_suite_failure():492 @lcc.suite("MySuite")493 class mysuite:494 def setup_suite(self):495 lcc.log_error("something bad happened")496 @lcc.test("Some test")497 def sometest(self):498 pass499 report = run_suite_class(mysuite)500 setup = _get_suite_setup(report)501 assert setup.status == "failed"502 assert setup.start_time is not None503 assert setup.end_time is not None504 assert setup.get_steps()[0].get_logs()[0].message == "something bad happened"505 assert not setup.is_successful()506def test_setup_suite_without_content():507 @lcc.suite("MySuite")508 class mysuite:509 def setup_suite(self):510 pass511 @lcc.test("Some test")512 def sometest(self):513 pass514 report = run_suite_class(mysuite)515 assert _get_suite_setup(report) is None516def test_teardown_suite_success():517 @lcc.suite("MySuite")518 class mysuite:519 @lcc.test("Some test")520 def sometest(self):521 pass522 def teardown_suite(self):523 lcc.log_info("some log")524 report = run_suite_class(mysuite)525 teardown = _get_suite_teardown(report)526 assert teardown.status == "passed"527 assert teardown.start_time is not None528 assert teardown.end_time is not None529 assert teardown.get_steps()[0].get_logs()[0].message == "some log"530 assert teardown.is_successful()531def test_teardown_suite_failure():532 @lcc.suite("MySuite")533 class mysuite:534 @lcc.test("Some test")535 def sometest(self):536 pass537 def teardown_suite(self):538 check_that("val", 1, equal_to(2))539 report = run_suite_class(mysuite)540 teardown = _get_suite_teardown(report)541 assert teardown.status == "failed"542 assert teardown.start_time is not None543 assert teardown.end_time is not None544 assert teardown.get_steps()[0].get_logs()[0].is_successful is False545 assert not teardown.is_successful()546def test_teardown_suite_without_content():547 @lcc.suite("MySuite")548 class mysuite:549 @lcc.test("Some test")550 def sometest(self):551 pass552 def teardown_suite(self):553 pass554 report = run_suite_class(mysuite)555 assert _get_suite_teardown(report) is None556def test_setup_test_session_success():557 @lcc.suite("MySuite")558 class mysuite:559 @lcc.test("Some test")560 def sometest(self, fixt):561 pass562 @lcc.fixture(scope="session")563 def fixt():564 lcc.log_info("some log")565 report = run_suite_class(mysuite, fixtures=[fixt])566 setup = report.test_session_setup567 assert setup.status == "passed"568 assert setup.start_time is not None569 assert setup.end_time is not None570 assert setup.get_steps()[0].get_logs()[0].message == "some log"571 assert setup.is_successful()572def test_setup_test_session_failure():573 @lcc.suite("MySuite")574 class mysuite:575 @lcc.test("Some test")576 def sometest(self, fixt):577 pass578 @lcc.fixture(scope="session")579 def fixt():580 lcc.log_error("something bad happened")581 report = run_suite_class(mysuite, fixtures=[fixt])582 setup = report.test_session_setup583 assert setup.status == "failed"584 assert setup.start_time is not None585 assert setup.end_time is not None586 assert setup.get_steps()[0].get_logs()[0].message == "something bad happened"587 assert not setup.is_successful()588def test_setup_test_session_without_content():589 @lcc.suite("MySuite")590 class mysuite:591 @lcc.test("Some test")592 def sometest(self, fixt):593 pass594 @lcc.fixture(scope="session")595 def fixt():596 pass597 report = run_suite_class(mysuite, fixtures=[fixt])598 assert report.test_session_setup is None599def test_teardown_test_session_success():600 @lcc.suite("MySuite")601 class mysuite:602 @lcc.test("Some test")603 def sometest(self, fixt):604 pass605 @lcc.fixture(scope="session")606 def fixt():607 yield608 lcc.log_info("some log")609 report = run_suite_class(mysuite, fixtures=[fixt])610 teardown = report.test_session_teardown611 assert teardown.status == "passed"612 assert teardown.start_time is not None613 assert teardown.end_time is not None614 assert teardown.get_steps()[0].get_logs()[0].message == "some log"615 assert teardown.is_successful()616def test_teardown_test_session_failure():617 @lcc.suite("MySuite")618 class mysuite:619 @lcc.test("Some test")620 def sometest(self, fixt):621 pass622 @lcc.fixture(scope="session")623 def fixt():624 yield625 check_that("val", 1, equal_to(2))626 report = run_suite_class(mysuite, fixtures=[fixt])627 teardown = report.test_session_teardown628 assert teardown.status == "failed"629 assert teardown.start_time is not None630 assert teardown.end_time is not None631 assert teardown.get_steps()[0].get_logs()[0].is_successful is False632 assert not teardown.is_successful()633def test_teardown_test_session_without_content():634 @lcc.suite("MySuite")635 class mysuite:636 @lcc.test("Some test")637 def sometest(self, fixt):638 pass639 @lcc.fixture(scope="session")640 def fixt():641 yield642 report = run_suite_class(mysuite, fixtures=[fixt])643 assert report.test_session_teardown is None644def test_add_report_info():645 @lcc.suite("Some suite")646 class mysuite:647 @lcc.test("Some test")648 def sometest(self):649 lcc.add_report_info("some info", "some data")650 report = run_suite_class(mysuite)...

Full Screen

Full Screen

test_report.py

Source:test_report.py Github

copy

Full Screen

...83 class suite:84 @lcc.test("test")85 def test(self):86 lcc.log_info("some log")87 report = run_suite_class(suite)88 assert report.is_successful()89def test_is_successful():90 @lcc.suite("suite")91 class suite:92 @lcc.test("test")93 def test(self):94 lcc.log_error("some error")95 report = run_suite_class(suite)96 assert not report.is_successful()97def test_is_successful_with_disabled_test():98 @lcc.suite("suite")99 class suite:100 @lcc.test("test_1")101 def test_1(self):102 lcc.log_info("some log")103 @lcc.test("test_2")104 @lcc.disabled()105 def test_2(self):106 lcc.log_info("some log")107 report = run_suite_class(suite)108 assert report.is_successful()109def test_is_successful_with_failed_test():110 @lcc.suite("suite")111 class suite:112 @lcc.test("test")113 def test(self):114 lcc.log_error("some error")115 report = run_suite_class(suite)116 assert not report.is_successful()117def test_is_successful_with_failed_teardown():118 @lcc.suite("suite")119 class suite:120 @lcc.test("test")121 def test(self):122 lcc.log_info("some log")123 def teardown_suite(self):124 lcc.log_error("some error")125 report = run_suite_class(suite)126 assert not report.is_successful()127def test_check_report_message_template_ok():128 template = "{passed} test passed"129 assert check_report_message_template(template) == template130def test_check_report_message_template_ko():131 with pytest.raises(ValueError):132 assert check_report_message_template("{invalid_var}'")133@pytest.fixture()134def report_sample():135 @lcc.suite()136 class suite:137 @lcc.test()138 def test_1(self):139 pass140 @lcc.test()141 @lcc.disabled()142 def test_2(self):143 pass144 @lcc.test()145 def test_3(self):146 lcc.log_error("some issue")147 @lcc.test()148 def test_4(self):149 lcc.log_info("everything ok")150 return run_suite_class(suite)151def test_report_build_message_with_start_time(report_sample):152 assert str(CURRENT_YEAR) in report_sample.build_message("{start_time}")153def test_report_build_message_with_end_time(report_sample):154 assert str(CURRENT_YEAR) in report_sample.build_message("{end_time}")155def test_report_build_message_with_duration(report_sample):156 report_sample.end_time = report_sample.start_time + 1157 assert report_sample.build_message("{duration}") == "1s"158def test_report_build_message_with_total(report_sample):159 assert report_sample.build_message("{total}") == "4"160def test_report_build_message_with_enabled(report_sample):161 assert report_sample.build_message("{enabled}") == "3"162def test_report_build_message_with_passed(report_sample):163 assert report_sample.build_message("{passed}") == "2"164def test_report_build_message_with_passed_pct(report_sample):...

Full Screen

Full Screen

test_cmd_top.py

Source:test_cmd_top.py Github

copy

Full Screen

...30 lcc.log_info("foobar")31 @lcc.test("test")32 def test(self):33 pass34 report = run_suite_class(suite)35 top_suites = TopSuites.get_top_suites(report, ResultFilter(grep=re.compile("foobar")))36 assert len(top_suites) == 137 assert top_suites[0][0] == "suite"38 assert top_suites[0][1] == 039 assert top_suites[0][3] == "100%"40def test_top_suites_cmd(tmpdir, cmdout):41 report = make_report([42 make_suite_result("suite1", tests=[make_test_result("test", start_time=0.1, end_time=1.0)]),43 make_suite_result("suite2", tests=[make_test_result("test", start_time=1.0, end_time=4.0)]),44 ])45 report_path = tmpdir.join("report.json").strpath46 save_report_into_file(report, report_path)47 assert main(["top-suites", report_path]) == 048 lines = cmdout.get_lines()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]...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful