def setup(): y1 = "this is the SETUP function" y2 = "another message" log.high_level_step("module_phase_saved_pass-setup") # PASS CONDITION verify(True, "module_phase_saved_pass-setup-1:pass") verify(True, "module_phase_saved_pass-setup-2:pass")
def function_scoped_fix(request): """Function scoped setup and teardown fixture. Applied to functions that include it as an argument. Local variables added to aid plugin debugging only. :param request: object is used to introspect the "requesting" test function, class or module context. """ log.high_level_step("Fixture has params: {}".format(request.param)) def teardown(): log.high_level_step("function_phase_saved_pass-teardown") if request.param["w"]: verify(False, "teardown warning", warning=True) if request.param["s"]: verify(False, "teardown failed verification (saved)", raise_immediately=False) if request.param["i"]: verify(False, "teardown failed verification (raise immediately)") if request.param["a"]: assert False, "teardown regular assertion" # else setup has passed verify(True, "function_phase_saved_pass-teardown:pass", raise_immediately=False) request.addfinalizer(teardown) def setup(): log.high_level_step("function_phase_saved_pass-setup") verify(True, "function_phase_saved_pass-setup passed") setup()
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")
def setup(): y1 = "this is the SETUP function" y2 = "another message" log.high_level_step("class_scoped_fix-setup") # PASS CONDITION verify(True, "class_scoped_fix-setup-1:pass") verify(True, "class_scoped_fix-setup-2:pass")
def setup(): log.high_level_step("f_st1-setup") # PASS CONDITION verify(True, "function_phase_warning-setup:pass", raise_immediately=False) # WARNING CONDITION verify(False, "function_phase_warning-setup:warning", warning=True)
def setup(): log.high_level_step("function_phase_assert-setup") # PASS CONDITION verify(True, "function_phase_assert-setup:pass", raise_immediately=False) # STANDARD ASSERT FAILURE assert False, "function_phase_assert-setup:standard assert"
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")
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")
def setup(): log.high_level_step("function_phase_saved_failure-setup") # PASS CONDITION verify(True, "function_phase_saved_failure-setup:pass", raise_immediately=False) # FAIL CONDITION verify(False, "function_phase_saved_failure-setup:fail", raise_immediately=False)
def setup(): log.high_level_step("function_phase_saved_pass-setup") # PASS CONDITION verify(True, "function_phase_saved_pass-setup:pass", raise_immediately=False) # verify(False, "function_phase_warning-setup:warning", warning=True) # assert False setup_device_1() setup_device_2()
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"
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")
def setup(): log.high_level_step("function_phase_saved_pass-setup") if request.param["w"]: verify(False, "setup warning", warning=True) if request.param["s"]: verify(False, "setup failed verification (saved)", raise_immediately=False) if request.param["i"]: verify(False, "setup failed verification (raise immediately)") if request.param["a"]: assert False, "setup regular assertion" # else setup has passed verify(True, "function_phase_saved_pass-setup passed")
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")
def teardown(): log.high_level_step("function_phase_saved_pass-teardown") if request.param["w"]: verify(False, "teardown warning", warning=True) if request.param["s"]: verify(False, "teardown failed verification (saved)", raise_immediately=False) if request.param["i"]: verify(False, "teardown failed verification (raise immediately)") if request.param["a"]: assert False, "teardown regular assertion" # else setup has passed verify(True, "function_phase_saved_pass-teardown:pass", raise_immediately=False)
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")
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
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")
def test_expected_fail_strict(): # xFailed report (strict=False) log.high_level_step("----------------------------------------------------") log.high_level_step("expected to fail and fails (strict)") a = 0 b = 1 assert a == b, "Expected to fail"
def teardown(): log.high_level_step("function_phase_saved_pass-teardown") # PASS CONDITION verify(True, "function_phase_saved_pass-teardown:pass", raise_immediately=False)
def teardown(): z = "this is the TEARDOWN function" log.high_level_step("module_phase_saved_pass-teardown") # PASS CONDITION verify(True, "module_phase_saved_pass-teardown-1:pass") verify(True, "module_phase_saved_pass-teardown-2:pass")
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")
def test_param(a): log.high_level_step("Starting test with param a = {}".format(a)) verify(a > 0, "a fails", warn_condition=a > 1, warn_message="a warns")
def setup(): log.high_level_step("function_phase_saved_pass-setup") verify(True, "function_phase_saved_pass-setup passed")
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
def test_4_class_scope(self, class_scoped_fix): log.high_level_step("test_4_class_scope") verify(True, "test_4_class_scope:call-1:pass") verify(True, "test_4_class_scope:call-2:pass")
def teardown(): z = "this is the TEARDOWN function" log.high_level_step("class_scoped_fix-teardown") # PASS CONDITION verify(True, "class_scoped_fix-teardown-1:pass") verify(True, "class_scoped_fix-teardown-2:pass")
def test_1_module_scope(): """Test uses module scoped fixture only.""" log.high_level_step("test_module_scope_1") verify(True, "test_module_scope_1:call-1:pass") verify(True, "test_module_scope_1:call-2:pass")
def test_2_module_scope(function_scoped_fix): """Test uses module and function scoped fixtures.""" log.high_level_step("test_module_scope_2") verify(True, "test_module_scope_2:call-1:pass") verify(True, "test_module_scope_2:call-2:pass")
def test_unexpected_pass_strict(): log.high_level_step("----------------------------------------------------") log.high_level_step("expected to fail and unexpectedly passes (strict)") a = 1 b = 1 assert a == b, "Expected to fail but passes"