TestRun

This object define a given step in a test. It is created via calling the Test.AddTestRun() function.

class TestRun
ComposeVariables()

Returns a dictionary of all variable with the parents, if any replaces with values of the children.

Return type:

StringDict

EndAfter(*lst, **kw)

Helps control the order in which Processes should be shut down when the system has to stop the running processes. Useful when processes might have nanny processes that might restart other processes, or when certain state outputs are dependent on how processes are killed.

Parameters:

lst – These are the Process object{s) to start before this Process object.

EndBefore(*lst, **kw)

Helps control the order in which Processes should be shut down when the system has to stop the running processes. Useful when processes might have nanny processes that might restart other processes, or when certain state outputs are dependent on how processes are killed.

Parameters:

lst – These are the Process object{s) to start before this Process object.

StartAfter(*lst, **kw)

The same as StartBefore(), but in this case will start the provided processes after starting this process. See StartBefore() for details on arguments and examples.

Parameters:
  • lst – These are the Process object{s) to start before this Process object.

  • ready – Named argument that can be provided to tell when the next process should start. The value can be a number, which will tell in second how long to wait. If the value is a function, the function needs to return True when the state is ready, and False when it is not. This function should do a quick test and not block the system from running.

  • args – Extra named arguments that will be pass to the ready function.

StartBefore(*lst, **kw)

States that you want to start the provided Process object before the called object. The optional ready argument can be a number or function to tell when these objects should be ready before starting the next process. This is useful when certain states or time delays are needed before the next process can start. This function has to be added via named arguments. Likewise, arguments can be provided to the ready function via named arguments to help control behavior.

Parameters:
  • lst – These are the Process object{s) to start before this Process object.

  • ready – Named argument that can be provided to tell when the next process should start. The value can be a number, which will tell in second how long to wait. If the value is a function, the function needs to return True when the state is ready, and False when it is not. This function should do a quick test and not block the system from running.

  • args – Extra named arguments that will be pass to the ready function.

Example

Simple start A before B with no delay

A=tr.Processes.Process('a', ...)
B=tr.Processes.Process('b',...)
B.StartBefore(A)

Simple start A before B with 1.5 second delay by setting ready logic

A=tr.Processes.Process('a', ...)
A.ready=1.5
B=tr.Processes.Process('b',..)
B.StartBefore(A)

Simple start A before B with 1.5 second delay via setting it on the StartBefore

A=tr.Processes.Process('a', ...)
B=tr.Processes.Process('b',...)
B.StartBefore(A,ready=1.5)

Simple start A and A1 before B with custom function via setting it on the StartBefore

def custom_delay(file,size):
    # ...

A=tr.Processes.Process('a', ...)
A1=tr.Processes.Process('a1', ...)

B=tr.Processes.Process('b',...)
B.StartBefore(A,A1,ready=custom_delay,file="startup.log",size=1024)
property CleanupEvent: Event

Called to do any cleanup actions

Return type:

Event

property ContinueOnFail: bool

Controls if the test should continue running if this test run does not pass.

Return type:

bool

property DelayStart: float

Defines a number of seconds to delay the start of the object after it has become ready to start. This allows a different way to delay starting a Process or TestRun. Useful as a way to effectively “sleep” for a time period before the process or a TestRun starts

Example

Sets a delay in the of 2.5 second for a process to reload data

Test.Processes.Process("server",cmd="…")
Tr1=Test.AddTestRun()

# set some value for the server, Server takes at least two second to
# reload data
Tr1.Processes.Default="server_cfg -set value=2"
Tr1.StartBefore(Test.Processes.server)

# test that the value was loaded
Tr2=Test.AddTestRun()

# delay little over two second to give server time to load data
Tr1.Processes.Default.DelayStart=2.5
Tr1.Processes.Default="server_cfg -get value"
Tr1.Processes.Default.Streams..stdout.Content=testers.ContainsExpression("2","test that value = 2")

Sets a delay in the of 2.5 second for a TestRun to allow steps from the previous TestRun time to go through the system

tr = Test.AddTestRun()
tr.DelayStart=5 # delay 5 seconds before start the test run
tr.Processes.Default.Command = 'python diff.py'
tr.Processes.Default.ReturnCode=0
Return type:

float

property DisplayString

The display string used to describe the test run in the finial report

property Env: StringDict

The shell environment used for running commands. Returns a dictionary type object. Items are in the dictionary are only the those set at the current scope. This mean a variable set of the Test object will not be seen at the TestRun object. To get a fully composed set of values including those of parent TestRun or Test object call the ComposeEnv() API. Values set at a lower scope override values defined in a parent scope.

Example

use a special feature for the test

Test.Env["USE_MY_FEATURE1"] = "1"
Return type:

StringDict

property FinishedEvent: Event

Called after the logic of the runnable has finished

Return type:

Event

property Name

The name of the TestRun

Getter:

returns the name

property Ready

Option number or function that defines when the Process is considered to be ready. To be ready means that we can start another process that should start after this process. If the value is a number, it will be used as a number of seconds to wait before starting the process. Otherwise this is normally a function defined in the When space.

This is exist on TestRun and Test objects however at the moment is does not have any affect.

property RunDirectory

Returns the directory this test will run in. This maps to a directory under the sandbox root directory.

property RunningEvent: Event

Called every .1 of second while the runnable logic is executing

Return type:

Event

property Setup

The setup object for this given process. See Setup for more information.

property SetupEvent: Event

Called to do any setup logic

Return type:

Event

property StartedEvent: Event

Called after the main logic has started

Return type:

Event

property StartingEvent: Event

Called before we start the main logic of the runnable.

Return type:

Event

property TestDirectory

Returns the directory where the test file exists

property TestFile

Returns the name of the test file that defines this test

property TestRoot

Returns the root directory in which autest start scanning for tests

property Variables

Defines a special Variables object that allows for the dynamic setting of new values. Allows for setting of state to be shared for defining tests. Values are shared and can be overridden on child objects.

Example:

Define a new variable for Port value

Test.Variables.Port = 8080

tr=Test.AddTestRun()
tr.Processes.Default="curl localhost:{0}".format(tr.Variables.Port)

Testable properties:

property StillRunningBefore

Tests that the process is still running before the test run start running

Event : Setup

Default type : Process object

Example:

Test the server process is still running before the second Test Run starts

p=Test.Processes.Process("ts","myserver –port 8080")
t1 = Test.AddTestRun("server started properly")
# ...

t2 = Test.AddTestRun("server started properly")
t2.StillRunningBefore=p
property StillRunningAfter

Tests that the process is still running before the test run start running

Event : Finished

Default type : Process object

Example:

Test the server process is still running after the test run is command finishes

p=Test.Processes.Process("ts","myserver –port 8080")
t1 = Test.AddTestRun("server started properly")
t1.StillRunningAfter=p
# ...
property NotRunningBefore

Tests that the process is not running before the test run start running

Event : Setup

Default type : Process object

property NotRunningAfter

Tests that the process is still running before the test run start running

Event : Finished

Default type : Process object

Example:

Test the server process stopped

P = Test.Processes.Default.Command="myserver –port 8080"
t = Test.AddTestRun("server started properly")
t.Processes.Default.Command = "kill-server"
t.NotRunningAfter = p