Beispiel #1
0
 def setup():
     log.high_level_step("function_phase_fail-setup")
     # PASS CONDITION
     verify(True, "function_phase_fail-setup:pass", raise_immediately=False)
     # FAIL CONDITION
     verify(False, "function_phase_fail-setup:fail", raise_immediately=True)
     log.detail_step("function_phase_fail-setup: This should not print")
Beispiel #2
0
    def test_class_1(self, c_st0, f_st1):
        log.high_level_step("Test the pytest-verify plugin: test class 1")
        log.high_level_step("Saving results with test phase and phase scope")

        log.detail_step("Test a verification that passes")
        x = True
        verify(x is True, "test_class_1:call:test x is True (pass)")

        log.detail_step("End of test_class_1")
Beispiel #3
0
def test_expected_fail_less():
    log.high_level_step("----------------------------------------------------")
    log.high_level_step("expected fail less than with reason")
    log.detail_step("sys.version_info = {}".format(sys.version_info))
    a = 0
    b = 1
    # Test xFails if this asserts, and unexpectedly passes if not (because
    # version is not > 3.3)
    # FIXME if the above comment is on next line it prints in the traceback
    # up to the comma
    assert a == b, "Fail"
Beispiel #4
0
    def test_class_0(self, c_st0, f_st1):
        log.high_level_step("Test the pytest-verify plugin: test class 0")
        log.high_level_step("Saving results with test phase and phase scope")

        log.detail_step("Test a verification that passes")
        x = True
        verify(x is True, "test_class_0:call:test x is True (pass)")

        # log.detail_step("Test a verification that fails")
        # x = False
        # verify(x is True, "test1:call:test x is True (fail)",
        #        raise_immediately=False, stop_at_test=True)

        log.detail_step("End of test_class_0")
Beispiel #5
0
def test_assert_traceback():
    log.high_level_step("Test the pytest-verify plugin")
    log.high_level_step("Standard assert traceback test")

    def stack_l3_assert(k):
        print "Finally verifying x, j, k"
        assert k is True, "test k is True (assert-fail)"

    def stack_l2_assert(j):
        print "In stack_l2 function"
        print "about to call stack_l3..."
        stack_l3_assert(j)

    def stack_l1_assert(i):
        stack_l2_assert(i)

    x = False
    stack_l1_assert(x)

    log.detail_step("End of test_assert_traceback")  # Should not execute
Beispiel #6
0
def test_basic_traceback():
    log.high_level_step("Test the pytest-verify plugin")
    log.high_level_step("Basic traceback test")

    x = True
    verify(x is True, "Check x is true (passes)")
    y = False
    verify(y is True, "Check y is true (fails)", raise_immediately=False)

    log.detail_step("Test a function call as fail condition (fails)")

    def is_it_true(it):
        return it is True
    y = False
    verify(is_it_true(y), "test y is True (fail condition in function)",
           raise_immediately=False)

    log.detail_step("Check traceback to call to verify over multiple stack "
                    "levels")

    def stack_l3(k):
        print "Finally verifying x, j, k"
        verify(k is True, "test k is True (fail)", raise_immediately=False)

    def stack_l2(j):
        print "In stack_l2 function"
        print "about to call stack_l3..."
        stack_l3(j)

    def stack_l1(i):
        stack_l2(i)

    x = False
    stack_l1(x)

    log.detail_step("Test traceback depth past test function (into pytest "
                    "source)")
    verify(x is True, "Check x is true (fail)", raise_immediately=False,
           stop_at_test=False)

    log.detail_step("End of test_basic_traceback")
Beispiel #7
0
def test_phases_0(f_st0):
    log.high_level_step("Test the pytest-verify plugin 0")
    log.high_level_step("Saving results with test phase and phase scope")

    log.detail_step("Test a verification that passes")
    x = True
    verify(x is True, "test0:call:test x is True (pass)")

    log.detail_step("Test a verification that fails")
    x = False
    verify(x is True,
           "test0:call:test x is True (fail)",
           raise_immediately=False,
           stop_at_test=True)

    log.detail_step("End of test_phases_0")
Beispiel #8
0
def test_phases_2(f_st0):
    log.high_level_step("Test the pytest-verify plugin")
    log.high_level_step("Basic use of verify conditions")

    log.detail_step("Test a verification that passes")
    x = True
    verify(x is True, "call:test x is True (pass)")

    log.detail_step("Test a verification that fails")
    x = False
    verify(x is True, "call:test x is True (fail)", raise_immediately=False,
           stop_at_test=True)

    # assert (x is
    #         True), "call:FOO with a ver long " \
    #               "message over 2 lines"

    log.detail_step("End of test_phases_2")
Beispiel #9
0
def test_full_traceback():
    log.high_level_step("Test the pytest-verify plugin")
    log.high_level_step("Full traceback test")

    log.detail_step("Ensure there is no traceback for passed verifications")
    x = True
    verify(x is True, "Check x is true (passes)")

    log.detail_step("Ensure default behaviour is short trace back")
    x = False
    verify(x is True,
           "Check x is true (fails - call line tb)",
           raise_immediately=False)

    log.detail_step("Test no change when full_method_trace is set to False")
    x = False
    verify(x is True,
           "Check x is true (fails - call line tb)",
           raise_immediately=False,
           full_method_trace=False)

    log.detail_step("Test full function traceback is printed when "
                    "full_method_trace is set to True")
    x = False
    verify(x is True,
           "Check x is true (fails - full func tb)",
           raise_immediately=False,
           full_method_trace=True)

    log.detail_step("Test a function call as fail condition (fails)")

    def is_it_true(it):
        return it is True

    y = False
    verify(is_it_true(y),
           "test y is True (fail condition in function)",
           raise_immediately=False,
           full_method_trace=True)

    log.detail_step("Check traceback to call to verify over multiple stack "
                    "levels")

    def stack_l3(k):
        print "Finally verifying x, j, k"
        verify(k is True,
               "test k is True (fail)",
               raise_immediately=False,
               full_method_trace=True)

    def stack_l2(j):
        print "In stack_l2 function"
        print "about to call stack_l3..."
        stack_l3(j)

    def stack_l1(i):
        stack_l2(i)

    x = False
    stack_l1(x)

    log.detail_step("Test traceback depth past test function (into pytest "
                    "source)")
    verify(x is True,
           "Check x is true (fail)",
           raise_immediately=False,
           full_method_trace=True,
           stop_at_test=False)

    log.detail_step("End of test_full_traceback")
Beispiel #10
0
def test_verify_basic_usage():
    log.high_level_step("Test the pytest-verify plugin")
    log.high_level_step("Basic use of verify conditions")

    log.detail_step("Test a verification that passes")
    x = True
    verify(x is True, "test x is True (pass)")

    log.detail_step("Test a verification that fails")
    x = False
    verify(x is True, "test x is True (fail)", raise_immediately=False)

    log.detail_step("Test a function call as fail condition")

    def is_it_true(it):
        return it is True

    y = True
    verify(is_it_true(y),
           "test y is True (fail condition in function)",
           raise_immediately=False)

    log.detail_step("Test a verification that warns")
    x = False
    verify(x is True, "test x is True (warning)", warning=True)

    log.detail_step("Test a verification that passes initial failure check "
                    "then warns on a second condition")
    x = True
    y = False
    verify(x is True,
           "test x is True (initial pass)",
           warn_condition=y is True,
           warn_message="test y is True (initial pass->warning)")

    log.detail_step("Test a variable that falls within initial range but "
                    "fails a stricter warning range")
    x = 2
    verify(0 < x < 4,
           "test x in range",
           warn_condition=1 < x < 3,
           warn_message="test x is in a narrower range (pass)")

    x = 3
    verify(0 < x < 4,
           "test x in range",
           warn_condition=1 < x < 3,
           warn_message="test x is in a narrower range (warning)")

    x = 4
    verify(0 < x < 4,
           "test x in range (fail)",
           warn_condition=1 < x < 3,
           warn_message="test x is in a narrower range")

    log.detail_step("End of test_verify_basic_usage")
Beispiel #11
0
def test_expected_fail_greater():
    log.high_level_step("----------------------------------------------------")
    log.high_level_step("expected fail greater than with reason")
    log.detail_step("sys.version_info = {}".format(sys.version_info))
    a = 0
    b = 1
Beispiel #12
0
def test_phases_setup_6(function_phase_saved_pass):
    log.high_level_step("test_phases_setup_wrapper_6 - paths 2, 5, 6")
    log.detail_step("call function will execute")
    verify(True, "test_phases_setup_wrapper_6:call:pass")
    log.high_level_step("test_phases_setup_wrapper_6 - call function complete")
Beispiel #13
0
def test_phases_setup_5(function_phase_warning):
    log.high_level_step("test_phases_setup_wrapper_5 - paths 2, 4, 6")
    log.detail_step("if continue_on_setup_failure is enabled the call "
                    "function will execute")
    verify(True, "test_phases_setup_wrapper_5:call:pass")
    log.high_level_step("test_phases_setup_wrapper_5 - call function complete")
Beispiel #14
0
def test_phases_setup_4(function_phase_saved_failure):
    log.high_level_step("test_phases_setup_wrapper_4 - paths 2 and 3")
    log.detail_step("if continue_on_setup_failure is enabled the call "
                    "function will execute")
    verify(True, "test_phases_setup_wrapper_4:call:pass")
    log.high_level_step("test_phases_setup_wrapper_4 - call function complete")
Beispiel #15
0
def test_phases_setup_3(function_phase_no_saved):
    log.high_level_step("test_phases_setup_wrapper_3 - path 2")
    log.detail_step("no saved results from setup function")
    verify(True, "test_phases_setup_wrapper_3:call:pass")
    log.high_level_step("test_phases_setup_wrapper_3 - call function complete")