Package: pytest-oot
pytest-oot implements a simple way to write a test step for test engineers.
This plug-in use test_steps module to implement the whole things.The test engineer can simply create test_*.oot file to use a simple case/step language,
by using the operators and options defined in test_steps module, or user-defined by you.For detailed operators and options for steps, please refer to test_steps module:https://pypi.python.org/pypi?:action=display&name=test_stepsNote: while using this plug-in,
you do not need pytest-autochecklog any more. All functions have been included.Install pytest-ootpip install pytest-ootExample for test_*.oot fileOnce the plug-in is installed, the pytest will automatically collect test_*.oot files
to get cases, and run each items in the files. In a test_*.oot file, each case is
a test item, and each line under it is a test step. For each test step, the syntax is
the same as a code string in checks(“code string”) function defined in test_steps module.Example file: test_number.oot (you can get it from the source package)# Any words after # in a line are just comments# One file is a test suite. The test suite descriptiontest_suite:Trial1# Identify the test bed file, currently .py file is supported# similar as 'import testbed.py' in test*.py file# .yaml file is support too. You can use: (see more information in TestSteps package)# test_bed: example.test.testbed.yamltest_bed:example.test.testbed.py# A case starts from a case_idString, the description is in the bracket# This is to define one case, just like a function or method in a .py file# case_id1 means the function name is "id1"case_id1(NumberBaseaddfunction):# under a case, there could be multiple test steps, one step in one line# step format: expression1 operator expression2 options# An expression can use any objects defined in test bed file# operator supports:#   ==(equal to), !=(not equal to), >(larger than), <(less than), >=, <=,#   =~(for string, contains, e.g. "hello world" =~ "llo", regex allowed#   !~ (not contain)# the following step is just like:#   checks( "num1.add(3,4,5,6) == 23 -t 3" )# in a python file, in which test_steps module is used.num1.add(3,4,5,6)==23-t3num1.add(var1,var2,var3)==18case_id2(NumberBasemultiplefunction):num1.multiple(2,4,5)==200case_id3(NumberChangetest):# Every line under the case line is a step of a case# there could be multiple lines; each line follows the format:#   obj.method([parameter1 [,parameter 2 [, ...]]] operator ExpectedValue -options# For details, see guidance ....# options:# --timeout 30 == -t 30: fail if the step could not complete in 30 seconds# --repeat 30 == -r 30: repeat per second if fail until pass, timeout in 30s# --duration 30 == -d 30: duration of the step is 30s, if completed early, just wait until 30s# --expectedfail == -x true == -x: If step fail, then report pass# --skip == -s: just skip this step#num1.add(4)num2.add(3,4,5,6)==23num2.multiple(4,5)==460-xTrue-t12-r10num3.add(3,4,var2)==1000--skip-t25case_id4(ReverseStringtest):string1.range(1,4)=='dlr'-d6case_async1(Totestasyncactions-timeout)num_async.addw(var100,var100)==100num_async.data_sync()-t18num_async.get_value()==300case_async2(Totestasyncactions-repeat)num_async.addw(var100,var100)>=300num_async.get_value()==500--repeat20Note: the testbed file is a python file, which define all the variables and objects to be used in the test.
If it reports the testbed module could not be imported, please change the module path
to make it right.Operators & OptionsSupported Operators by default:== (eq), != (ne), < (lt), > (gt), <= (le), >=(ge), =~(match), !~(unmatch), =>(has), !>(hasnt)Again, all operators defined in test_steps are supported, and you can also define them by yourself.Supported Options by default:-t 30   or --timeout 30    in checks()             means       timeout=30    in check()
-r 10   or --repeat  10    in checks()             means       repeat=10
-d 10   or --duration 10                          means       duration=10
-x  or --xfail or -x True or --xfail True         means       xfail=True
-w  or --warning  or -w True  or --warning True   means       warning=True
-s  or --skip     or -s True  or --skip True      means       skip=True
-e MyException                                    means       exception=MyException
-p pass_str or --passdesc pass_str                means       passdesc=pass_str
-f fail_str or --faildesc fail_str                means       faildesc=fail_strTest bedIf you are using a test_*.oot file, you need to usetestbed = [module.]testbedfilenameto import all the objects defined in the testbedfilename.py file.Example for using step functions in a test_*.pyOf course, you can directly use test_steps functions in your test_*.py test scripts files.
Please refer to test_steps module for details. Some basic examples as below:Examples (Quick Start):The Simplest step:check("num1.add(3,4,5) == 23")It is similar as:assertnum1.add(3,4,5)==23very simple, right? (we do not consider advanced features here, e.g.
auto-logging)Step with non-python-defined operatorscheck("string1.range(1..4) !~ r'\w\-\w'")Perl-like condition, =~ means ‘contains’, and !~ means ‘not contains’.
btw, regex can be used. The step is like:importreassertnotre.compile(r'\w\-\w').find(string1.range(1..4))Step with timeout optioncheck("num_async.data_sync() -t 15")A little complicated, -t means timeout. In this step, a time-out timer
is set to 15 seconds. It means this step is allowed to be completed
in 15 seconds, otherwise, it fails. no op (==, <, >, =~, etc.) in this step,
it means no assert required to check the return valueThis is implemented by forking another thread to run the step.
Considering some tests require to wait for a response, but how long?
this can be usefulStep with repeat option:check("num_async.get_value() == 500 --repeat 20")Another option –repeat (same as -r).
The step means the step will be re-run every another second
in total 20 seconds, until the condition comes trueIf the condition is always false in 20 seconds, then the step failsStep with multiple optionscheck("num2.multiple(4,5) == 460 -x True -t 12 -r 10")Multiple options for one step-x (--expectedfail): pass if the condition is not met
-t (--timeout): set a timeout timer
-r (--repeat): repeat this step in 10 seconds until it comes true
   (here false actually due to -x), or timeoutUse steps function to execute multiple stepschecks('''
    num1.add(4)
    num2.add(3,4,5,6) == 23
    num2.multiple(4,5) == 460 -x True -t 12 -r 10
    num3.add(3,4,var2) == 1000 --skip -t 20
''')Or you are lazy, just use s function like this:c("num2.multiple(4,5) == 460 -x True -t 12 -r 10")c('''
     num1.add(4)
     num2.add(3,4,5,6) == 23
     num2.multiple(4,5) == 460 -x True -t 12 -r 10
     num3.add(3,4,var2) == 1000 --skip -t 25
 ''')Note: each line of the code strings in the checks functions can be a step in test_*.oot file.Hookspytest-oot is to support multiple hooks for operator, logs, and options, refer to test_steps.
Please send mails tosteven004@gmail.comif you have any comments or suggestionsLicenseThis software is licensed under theMIT license.© 2015 Steven LI