Test

Defines a given test and all related logic. There is one Test object per test file. A given test can contain many different steps refereed to a TestRuns. Some of the member of the Test object may also be accessed globally without reference to the Test object, such as the Setup member.

class Test
AddTestRun(displaystr=None, name='tr')

Creates a new TestRun object. The order in which these are created controls the order in which they run.

Parameters:
  • displaystr (str) – A description of what the test run does. Used in the reports to help clarify what is happening If not defined a general auto generated value will be used based on the name property

  • name (str) – The name of the test run. The provided value will be appended with a value of “-{num of test runs so far}” Used to define locations on disk under the sandbox. Useful to help define what a given test run maybe doing. If not defined a default value of “tr” will be used.

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.

SkipIf(*lst)

This method takes one or more conditions as defined by the condition namespace. If any of the conditions are true, the test will be skipped

Parameters:

*lst

condition(s) to check to determine if a test should be skipped.

Examples

Skip test if platform is not Windows

Test.SkipIf(Condition.IsNotPlatform('windows'))
SkipUnless(*lst)

This method takes one or more conditions as defined by the condition namespace. If any of the conditions are false, the test will be skipped

Parameters:

*lst

condition to test if a test should be skipped.

Examples

Run test if and only if gcc exists and the platform is a POSIX or windows

Test.SkipUnless(
Condition.HasProgram(
    "gcc"
),
Condition.IsPlatform('posix','windows')
)
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. Can be set to True or False.

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 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 test

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 RunSerial: bool

A Boolean value of True or False. Stated that this test has to run be itself in serially without any other tests running. This prevents cases in which the test, for whatever reason, cannot run in parallel with another test. By default, this value is False. It only has effect if the –jobs option is greater than 1

Return type:

bool

property RunningEvent: Event

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

Return type:

Event

property Setup: Setup

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

Return type:

Setup

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 Summary: str

Summary of what this test is about and or does.

Examples

Test.Summary="Test the loading of config file"
Return type:

str

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)