Skip to content

Check Step functions

Steven Li edited this page Mar 23, 2017 · 7 revisions

Check/Step functions are wrapped functions for pass/fail auto-log functions, it will execute the pass/fail functions and log the results, and also provide different options to make a complicated step into one line.

e.q. the following two lines of code is identical from the functional point of view (both pass)

has(googleurlconn.search("TestSteps Python"), "steven004")
check(' googleurlconn.search("TestSteps Python") => "steven004" ')

However, the following function provide timeout option, it will wait 10s for response, then fail if no response

check(' googleurlconn.search("TestSteps Python") => "steven004" ', timeout=10)

The following option will try 5 times if not passed (you will see you will be lucky most time :-)) check(' lucknumber(10) > 7 ', repeat=5)

Options predefined

- timeout: e.g. timeout=30, fail if the step could not complete in 30 seconds
- repeat: e.g. repeat=20, repeat in another second if fail until pass, timeout in 20s
- duration: e.g. duration=15, stay in this step for 15 seconds, even it completed shortly
- xfail: e.g. xfail=True, expected failure, report pass when fail, vice versa
- warning: e.g. warning=True, Pass the step anyway, but log a warning message if the condition is not met
- skip: e.g. skip=True, just skip this case.
- exception: e.g. exception=NameError, expected exception will be raised. pass if so, or fail
- passdesc: e.g. passdesc="the string to log if passed" (replace the code_string in the log)
- faildesc: e.g. faildesc="the string to log if failed" (replace the code_string in the log)

step(code_string, globals=None, locals=None, **kwargs)

check(code_string, globals=None, locals=None, **kwargs)

Both functions are the same, just another name. See options above

steps(code_lines, globals=None, locals=None, batch=False)

checks(code_lines, globals=None, locals=None, batch=False)

s(code_lines, globals=None, locals=None, batch=False)

the 3 functions are the same. Why use 3 names, I do not know really. Steps functions could run a few steps in one string. This is actually for pytest-oot plug-in. You could use in normal cases too.

The format is like:

    checks('''
        my_add(3,4,5) == my_mul(3,4)    -d 3
        my_add(3,4,6) == 12     -w
        my_mul(3,4,5) > 20      -w  -t 1
        my_mul(2,3)/my_add() == 5   -e ZeroDivisionError
        my_mul(2,3)*my_add(1) >= 5  -p "result is 5, pass"  -f "result <= 5"
        my_mul(2,3)*my_add(3) < 5   -x
        my_mul(4,5)*5 == 0  -s
        my_add(3,4) >= 11   -r 5
    ''')

Get more information from lesson4 in the test_example folder in source code of this package.

Init_testbed function

Pre-defined pass/fail functions

Test Step/steps functions

Test Log functions

Functions to add functions

Clone this wiki locally