Process

Defines a system process that can run as part of the test.

class Process
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 Command: Optional[str]

The command used to start the process

Return type:

Optional[str]

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

Forces the use of a shell when running the command. Normally AuTest will try to detect if there shell related commands or syntax in the command and will only spawn a shell in those cases. However in certain cases it fails to get this correct and need to be explicitly told to use the shell

Return type:

bool

property Name: str

The name or ID of the process

Getter:

returns the name

Return type:

str

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

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

Return type:

str

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 StartupTimeout: float

This is the value of how long AuTest will wait for the given process to start and be considered ready before it will stop the process and report an error. Set this value to allow for more or less time.

Return type:

float

property StreamOutputDirectory: str

The path to the where all stream files will be written to

Return type:

str

property TestDirectory: str

Returns the directory where the test file exists

Return type:

str

property TestFile: str

Returns the name of the test file that defines this test

Return type:

str

property TestRoot: str

Returns the root directory in which autest start scanning for tests

Return type:

str

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)
property Streams

An object that defines a number of streams and virtual streams of the process. See Streams for more information.

Testable properties:

property ReturnCode

Test that the return code equals to the expected value. If None, it is expected the process will be killed and will not be able to return a value.

Event : Finished

Default type : Integer

property Time

Test that the process finished within the time in seconds provided by default. This does not kill the process. It will only report that after the process finished that it failed meet the requirement of the test.

Event : Finished

Default type : float

property TimeOut

Stops the process if the process is still running after the time provided in seconds by default.

Event : Running

Default type : float