Esempio n. 1
0
def test_teardown_test_session_after_test_failure_and_test_success():
    marker = []

    @lcc.fixture(scope="session")
    def fixt():
        marker.append("test_session_setup")
        yield 1
        marker.append("test_session_teardown")

    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Test 1")
        def test_1(self, fixt):
            marker.append("test_1")
            1 / 0

        @lcc.test("Test 2")
        def test_2(self):
            marker.append("test_2")

    run_suite_class(MySuite, fixtures=[fixt])

    assert marker == [
        "test_session_setup", "test_1", "test_2", "test_session_teardown"
    ]
Esempio n. 2
0
def test_run_with_fixtures_dependencies_in_test_scope():
    # in this test, fixture dependency is set on fixture alphabetical inverse
    # order to highlight a bad dependency check implementation that use set data type

    marker = []

    @lcc.fixture(names=["fixt_3"], scope="test")
    def fixt3():
        return 2

    @lcc.fixture(names=["fixt_2"], scope="test")
    def fixt2(fixt_3):
        return fixt_3 * 3

    @lcc.fixture(names=["fixt_1"], scope="test")
    def fixt1(fixt_2):
        return fixt_2 * 4

    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Test")
        def test(self, fixt_1):
            marker.append(fixt_1)

    run_suite_class(MySuite, fixtures=[fixt1, fixt2, fixt3])

    assert marker == [24]
Esempio n. 3
0
def test_fixture_name_scopes():
    fixts = []

    @lcc.fixture(scope="session")
    def fixt_session_prerun(fixture_name):
        fixts.append(fixture_name)

    @lcc.fixture(scope="session")
    def fixt_session(fixture_name, fixt_session_prerun):
        fixts.append(fixture_name)

    @lcc.fixture(scope="suite")
    def fixt_suite(fixture_name, fixt_session):
        fixts.append(fixture_name)

    @lcc.fixture(scope="test")
    def fixt_test(fixture_name, fixt_suite):
        fixts.append(fixture_name)

    @lcc.suite("suite")
    class suite:
        @lcc.test("test")
        def test(self, fixt_test):
            pass

    run_suite_class(
        suite,
        fixtures=[fixt_session_prerun, fixt_session, fixt_suite, fixt_test])

    assert fixts == [
        "fixt_session_prerun", "fixt_session", "fixt_suite", "fixt_test"
    ]
Esempio n. 4
0
def test_run_with_suite_fixture_used_in_subsuite():
    marker = []

    @lcc.fixture(scope="suite")
    def fixt1():
        yield 1
        marker.append(2)

    @lcc.suite("MySuiteA")
    class MySuiteA:
        @lcc.test("Test")
        def test(self, fixt1):
            marker.append(fixt1)

        @lcc.suite("MySuiteB")
        class MySuiteB:
            @lcc.test("Test")
            def test(self, fixt1):
                marker.append(fixt1)

            @lcc.suite("MySuiteC")
            class MySuiteC:
                @lcc.test("Test")
                def test(self, fixt1):
                    marker.append(fixt1)

    run_suite_class(MySuiteA, fixtures=[fixt1])

    assert marker == [1, 2, 1, 2, 1, 2]
Esempio n. 5
0
def test_report_detailed_with_filter(tmpdir, cmdout):
    run_suite_class(mysuite, tmpdir=tmpdir, backends=[JsonBackend()])

    assert main(["report", tmpdir.strpath, "--failed"]) == 0

    cmdout.dump()
    cmdout.assert_substrs_in_line(0, ["My Test 1"])
    cmdout.assert_substrs_in_line(1, ["mysuite.mytest1"])
    cmdout.assert_substrs_in_line(3, ["My Test 1"])
    cmdout.assert_substrs_in_line(5, ["ERROR", "failure"])
    cmdout.assert_lines_nb(9)
Esempio n. 6
0
def test_report_detailed_with_arguments(tmpdir, cmdout):
    run_suite_class(mysuite, tmpdir=tmpdir, backends=[JsonBackend()])

    assert main(["report", tmpdir.strpath, "--explicit", "--max-width=80"]) == 0

    cmdout.dump()
    cmdout.assert_substrs_in_line(0, ["FAILED: My Test 1"])
    cmdout.assert_substrs_in_line(1, ["mysuite.mytest1"])
    cmdout.assert_substrs_in_line(3, ["My Test 1"])
    cmdout.assert_substrs_in_line(5, ["ERROR", "failure"])
    cmdout.assert_substrs_in_line(8, ["My Test 2"])
    cmdout.assert_substrs_in_line(9, ["mysuite.mytest2"])
    cmdout.assert_substrs_in_line(10, ["n/a"])
    cmdout.assert_lines_nb(13)
Esempio n. 7
0
def test_setup_suite():
    marker = []

    @lcc.suite("MySuite")
    class MySuite:
        def setup_suite(self):
            marker.append("ok")

        @lcc.test("Some test")
        def sometest(self):
            pass

    run_suite_class(MySuite)

    assert marker
Esempio n. 8
0
def test_teardown_suite_after_test_failure():
    marker = []

    @lcc.suite("MySuite")
    class MySuite:
        def teardown_suite(self):
            marker.append("ok")

        @lcc.test("Some test")
        def sometest(self):
            1 / 0

    run_suite_class(MySuite)

    assert marker
Esempio n. 9
0
def test_get_fixture_unknown():
    marker = []

    @lcc.suite("mysuite")
    class mysuite:
        @lcc.test("mytest")
        def mytest(self):
            try:
                lcc.get_fixture("fixt")
            except ProgrammingError:
                marker.append("exception")

    run_suite_class(mysuite)

    assert marker == ["exception"]
Esempio n. 10
0
def test_setup_test():
    marker = []

    @lcc.suite("MySuite")
    class MySuite:
        def setup_test(self, test):
            marker.append(test.name)

        @lcc.test("Some test")
        def sometest(self):
            pass

    run_suite_class(MySuite)

    assert marker == ["sometest"]
Esempio n. 11
0
def test_teardown_test_after_test_failure():
    marker = []

    @lcc.suite("MySuite")
    class MySuite:
        def teardown_test(self, test, status):
            marker.append((test.name, status))

        @lcc.test("Some test")
        def sometest(self):
            1 / 0

    run_suite_class(MySuite)

    assert marker[0] == ("sometest", "failed")
Esempio n. 12
0
def test_get_fixture():
    marker = []

    @lcc.fixture(scope="session_prerun")
    def fixt():
        return 42

    @lcc.suite("mysuite")
    class mysuite:
        @lcc.test("mytest")
        def mytest(self, fixt):
            marker.append(lcc.get_fixture("fixt"))

    run_suite_class(mysuite, fixtures=[fixt])

    assert marker == [42]
Esempio n. 13
0
def test_fixture_name_multiple_names():
    fixts = []

    @lcc.fixture(scope="test", names=["fixt1", "fixt2"])
    def fixt(fixture_name):
        fixts.append(fixture_name)

    @lcc.suite("suite")
    class suite:
        @lcc.test("test")
        def test(self, fixt1, fixt2):
            pass

    run_suite_class(suite, fixtures=[fixt])

    assert sorted(fixts) == ["fixt1", "fixt2"]
def test_all_types_of_logs():
    @lcc.suite("MySuite")
    class mysuite:
        @lcc.test("Test 1")
        def test_1(self):
            lcc.log_debug("some debug message")
            lcc.log_info("some info message")
            lcc.log_warn("some warning message")

        @lcc.test("Test 2")
        def test_2(self):
            lcc.log_error("some error message")

    report = run_suite_class(mysuite)

    test = report.get_test("mysuite.test_1")
    assert test.status == "passed"
    step = test.steps[0]
    assert step.entries[0].level == "debug"
    assert step.entries[0].message == "some debug message"
    assert step.entries[1].level == "info"
    assert step.entries[1].message == "some info message"
    assert step.entries[2].level == "warn"

    test = report.get_test("mysuite.test_2")
    assert test.status == "failed"
    step = test.steps[0]
    assert step.entries[0].message == "some error message"
    assert step.entries[0].level == "error"
Esempio n. 15
0
def test_run_with_fixture_with_logs():
    marker = []

    @lcc.fixture()
    def test_fixture():
        lcc.log_info("setup")
        yield 1
        lcc.log_info("teardown")

    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Test")
        def test(self, test_fixture):
            lcc.set_step("Doing some test")
            lcc.log_info("some log")
            marker.append(test_fixture)

    report = run_suite_class(MySuite, fixtures=[test_fixture])

    assert marker == [1]

    steps = report.get_suites()[0].get_tests()[0].steps

    assert len(steps) == 3
    assert steps[0].description == "Setup test"
    assert steps[1].description == "Doing some test"
    assert steps[2].description == "Teardown test"
Esempio n. 16
0
def test_exception_abortsuite():
    @lcc.suite("MySuite")
    class MySuite:
        @lcc.suite("MyFirstSuite")
        class MyFirstSuite:
            @lcc.test("Some test")
            def sometest(self):
                raise lcc.AbortSuite("test error")

            @lcc.test("Some other test")
            def someothertest(self):
                pass

        @lcc.suite("MySecondSuite")
        class MySecondSuite:
            @lcc.test("Another test")
            def anothertest(self):
                pass

    assert_test_statuses(
        run_suite_class(MySuite),
        failed=["MySuite.MyFirstSuite.sometest"],
        skipped=["MySuite.MyFirstSuite.someothertest"],
        passed=["MySuite.MySecondSuite.anothertest"],
    )
Esempio n. 17
0
def test_setup_suite_error_because_of_fixture():
    marker = []

    @lcc.fixture(scope="suite")
    def fix():
        1 / 0

    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Some test")
        def sometest(self, fix):
            pass

        @lcc.test("Some other test")
        def sometest_bis(self):
            pass

        def teardown_suite(self):
            marker.append("must_not_be_executed")

    report = run_suite_class(MySuite, fixtures=[fix])

    assert_test_statuses(report,
                         skipped=["MySuite.sometest", "MySuite.sometest_bis"])
    assert not marker
Esempio n. 18
0
def test_run_with_fixture_using_test_method():
    marker = []

    @lcc.fixture()
    def test_fixture():
        return 1

    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Test")
        def test(self, test_fixture):
            marker.append(test_fixture)

    run_suite_class(MySuite, fixtures=[test_fixture])

    assert marker == [1]
def test_multiple_steps_on_different_threads():
    def thread_func(i):
        lcc.set_step(str(i), detached=True)
        time.sleep(0.001)
        lcc.log_info(str(i))
        lcc.end_step(str(i))

    @lcc.suite("MySuite")
    class mysuite:
        @lcc.test("Some test")
        def sometest(self):
            threads = [
                lcc.Thread(target=thread_func, args=(i, )) for i in range(3)
            ]
            for thread in threads:
                thread.start()
            for thread in threads:
                thread.join()

    report = run_suite_class(mysuite)

    test = get_last_test(report)
    remainings = list(range(3))

    for step in test.steps:
        remainings.remove(int(step.description))
        assert len(step.entries) == 1
        assert step.entries[0].message == step.description

    assert len(remainings) == 0
Esempio n. 20
0
def test_teardown_test_session_after_test_failure():
    marker = []

    @lcc.fixture(scope="session")
    def fixt():
        yield 1
        marker.append(1)

    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Some test")
        def sometest(self, fixt):
            1 / 0

    run_suite_class(MySuite, fixtures=[fixt])

    assert marker
Esempio n. 21
0
def test_test_failure():
    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Some test")
        def sometest(self):
            lcc.check_that("val", 1, lcc.equal_to(2))

    assert_test_failed(run_suite_class(MySuite))
Esempio n. 22
0
def test_test_success():
    @lcc.suite("MySuite")
    class MySuite:
        @lcc.test("Some test")
        def sometest(self):
            pass

    assert_test_passed(run_suite_class(MySuite))
Esempio n. 23
0
def test_run_with_fixture_used_in_setup_suite():
    marker = []

    @lcc.fixture(scope="suite")
    def fixt1():
        return 1

    @lcc.suite("MySuiteA")
    class MySuite:
        def setup_suite(self, fixt1):
            marker.append(fixt1)

        @lcc.test("sometest")
        def sometest(self):
            pass

    run_suite_class(MySuite, fixtures=[fixt1])

    assert marker == [1]
def test_simple_test():
    @lcc.suite("MySuite")
    class mysuite:
        @lcc.test("Some test")
        def sometest(self):
            pass

    report = run_suite_class(mysuite)

    assert_report_from_suite(report, mysuite)
def test_add_report_info():
    @lcc.suite("Some suite")
    class mysuite:
        @lcc.test("Some test")
        def sometest(self):
            lcc.add_report_info("some info", "some data")

    report = run_suite_class(mysuite)

    assert report.info[-1] == ["some info", "some data"]
Esempio n. 26
0
def test_get_fixture_bad_scope():
    marker = []

    @lcc.fixture(scope="test")
    def fixt():
        return 42

    @lcc.suite("mysuite")
    class mysuite:
        @lcc.test("mytest")
        def mytest(self, fixt):
            try:
                lcc.get_fixture("fixt")
            except ProgrammingError:
                marker.append("exception")

    run_suite_class(mysuite, fixtures=[fixt])

    assert marker == ["exception"]
Esempio n. 27
0
def test_get_fixture_not_executed():
    marker = []

    @lcc.fixture(scope="session_prerun")
    def fixt():
        return 42

    @lcc.suite("mysuite")
    class mysuite:
        @lcc.test("mytest")
        def mytest(self):
            try:
                lcc.get_fixture("fixt")
            except ProgrammingError:
                marker.append("exception")

    run_suite_class(mysuite)

    assert marker == ["exception"]
Esempio n. 28
0
def test_sub_suite_inline():
    @lcc.suite("MyParentSuite")
    class MyParentSuite:
        @lcc.suite("MyChildSuite")
        class MyChildSuite:
            @lcc.test("Some test")
            def sometest(self):
                pass

    assert_test_passed(run_suite_class(MyParentSuite))
Esempio n. 29
0
def test_teardown_test_error():
    @lcc.suite("MySuite")
    class MySuite:
        def teardown_test(self, test, status):
            1 / 0

        @lcc.test("Some test")
        def sometest(self):
            pass

    assert_test_failed(run_suite_class(MySuite))
Esempio n. 30
0
def test_teardown_suite_after_test_failure_and_test_success():
    marker = []

    @lcc.suite("MySuite")
    class MySuite:
        def teardown_suite(self):
            marker.append("teardown_suite")

        @lcc.test("Test 1")
        def test_1(self):
            marker.append("test_1")
            1 / 0

        @lcc.test("Test 2")
        def test_2(self):
            marker.append("test_2")

    run_suite_class(MySuite)

    assert marker == ["test_1", "test_2", "teardown_suite"]