pyats.aetest package

Module:

aetest

Description:

This module defines the base classes required to write testscripts. It’s name is a direct carry over from Tcl-ATS’s AEtest package.

In short, this module is designed to offer a similar look-and-feel of its Tcl counterpart, whilst leveraging and building based on the advanced object-oriented capabilities of the Python Language.

aetest can be broken down as follows:

  • Common Sections

  • Testcases

For more detailed explanation and usages, refer to aetest documentation on pyATS home page: http://wwwin-pyats.cisco.com/

Submodules

class pyats.aetest.base.Source(obj, objcls=None)

Bases: object

Source Class

This class is enables TestItems and TestContainer sorting (run) order mechanism. It does so by looking at each class’s source information (file & line number) and inheritance relationships.

This is needed to ensure the repeatability of test-script runs.

Rules:

  • CommonSetup & setup section always runs first

  • CommonCleanup & cleanup section always runs last

  • note that Common sections are never sorted versus testcase sections, so the sorting doesn’t differentiate.

  • if one class inherits another, the parent class is smaller than the inherited class

  • otherwise, classes are sorted by their order of appearance (line number) within the script module.

Example

>>> from MyTestScript import TestcaseA, TestcaseB
>>> items = [TestcaseA, TestcaseB]
>>> items.sort(key = Source)

built in __init__

stores the object-to-be-sorted internally and gathering some of its source information (used during sorting).

Parameters
  • (TestItem) (obj) –

  • (type) (objcls) –

class pyats.aetest.base.TestItem(uid, description=None, parent=None, parameters={}, **kwargs)

Bases: pyats.results.context.TestResultContext

Test Item class

Base class for all other test classes. TestItem objects contains the bare minimum information for definining a testable. When a TestItem is created, the user needs to pass in a uid and a description for the test item, as well as testable content via kwargs.

Notes

  • TestItems may contain other TestItems

  • TestItem has a parent (or None, in the case of top-level parent)

  • TestItem class is usually not used directly by the user, but rather inherited by its subclasses.

Parameters
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item

static aborted(reason=None, *, data=None, goto=None, from_exception=None)

Test Aborted

API to call when the current test item execution is aborted. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

classmethod apply_data(data)

API that allows the updating of TestItem class’s attributes using a dictionary input. This is exclusively used with datafile feature.

Note - this api avoids re-writing properties and updates the internal __dunder__ attributes instead.

Parameters

(dict) (data) –

apply_parameters(func, parameters, pargs=())

apply parameters

Applies parameters (funcargs) specified in the TestItem and return a partial function ready for the executor/caller to execute. Supports the current argument types:

  • keyword arguments

  • keyword only arguments

  • variable keyword arguments

  • argument defaults

  • keyword only argument defaults

Does NOT support variable positional arguments.

Internal parameters are prioritized above user parameters.

Parameters

(ParameterDict) (parameters) – to test func

Returns

Return type

partial function with all the funcargs filled

static blocked(reason=None, *, data=None, goto=None, from_exception=None)

Test Blocked

API to call when the current test item execution is blocked. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

property description

description

returns the test item description, shortcutting this description to be also the __doc__ attribute.

Type

Property

static errored(reason=None, *, data=None, goto=None, from_exception=None)

Test Errored

API to call when the current test item execution errored out. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static failed(reason=None, *, data=None, goto=None, from_exception=None)

Test Failed

API to call when the current test item execution is failed. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

property parameters

parameters

returns the dictionary of parameter name/values for this test item. a parameter is a name/value mapping that drives the test item to test and/or behave different.

Example

>>> t = TestItem(uid = 'test', description = '', parameters = {})
>>> t.parameters
{}
Type

Property

static passed(reason=None, *, data=None, goto=None, from_exception=None)

Test Passed

API to call when the current test item execution is passed. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static passx(reason=None, *, data=None, goto=None, from_exception=None)

Test Passx

API to call when the current test item execution result is passed with exception. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static skipped(reason=None, *, data=None, goto=None, from_exception=None)

Test Skipped

API to call when the current test item execution should be skipped. Terminates current execution.

Parameters
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

class pyats.aetest.base.TestableMeta(name, bases, attrs)

Bases: type

Testable Metaclass

Metaclass that creates the actual Testcase/Testscript classes. Used to hijack the TestContainer subclass creations in order to customize internal behaviors.

Example

>>> class Testcase(TestContainer, metaclass = TestableMeta):
...     pass
>>> class UserTestcase(Testcase):
...     uid = 'userid'
>>> assert UserTestcase.__uid__ == UserTestcase.uid
>>> assert type(UserTestcase) is property

Metaclass __init__

Metaclass api called after class is created. Used here to modify each class attribute/function and add source information.

Parameters
  • (str) (name) –

  • (list) (bases) –

  • (dict) (attrs) –

class pyats.aetest.commons.Common(uid=None, *args, **kwargs)

Bases: pyats.aetest.container.TestContainer

Common Section

Base class for CommonSetup and CommonCleanup. Used to just consolidate common-code instead of copy/pasting.

Note that all common sections are TestContainers, and are worthless until they contain one or more subsections.

built in __init__

Initializes a TestContainer class by finding out the class id definition & passing it upstream to parent TestItem.__init__.

Parameters
  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

source = <pyats.aetest.base.Source object>
class pyats.aetest.commons.CommonCleanup(uid=None, *args, **kwargs)

Bases: pyats.aetest.commons.Common

CommonCleanup class

CommonCleanup section removes (cleans) all configurations applied in the whole script, including those from CommonSetup, and all those lingering from the testcases. This section is unique within each test script, and is always run last.

Note

CommonCleanup section is optional within each script.

Example

>>> class ExampleCommonCleanup(aetest.CommonCleanup):
...     @subsection
...     def disconnect_all_devices(self):
...         pass

built in __init__

Initializes a TestContainer class by finding out the class id definition & passing it upstream to parent TestItem.__init__.

Parameters
  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

source = <pyats.aetest.base.Source object>
class pyats.aetest.commons.CommonSetup(uid=None, *args, **kwargs)

Bases: pyats.aetest.commons.Common

CommonSetup class

CommonSetup section contains the common configurations/inits required to run subsequent testcases within each test script. Each test script may only have a single CommonSetup class defined, and this CommonSetup class is then broken down into smaller subsection (methods with decorators). CommonSetup section runs first in all test scripts.

Note

CommonSetup section is optional within each script.

Example

>>> class ExampleCommonSetup(aetest.CommonSetup):
...     @subsection
...     def connect_devices(self):
...         pass

built in __init__

Initializes a TestContainer class by finding out the class id definition & passing it upstream to parent TestItem.__init__.

Parameters
  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

source = <pyats.aetest.base.Source object>
class pyats.aetest.discovery.BaseDiscovery(target)

Bases: object

Base Class for all discovery classes

discover()
order()
class pyats.aetest.discovery.BaseTestDiscovery(target)

Bases: pyats.aetest.discovery.BaseDiscovery

Base Class for test section discovery

class pyats.aetest.discovery.CommonDiscovery(target)

Bases: pyats.aetest.discovery.BaseTestDiscovery

Discovery Class for Common Sections, find subsections

discover()

Common section discovery

The discovery process for all common sections is the same: look for subsections. A subsection is basically a class method decorated with @subsection decorator.

Also checks whether this common container contains the correct objects. Eg, if test sections are found, then errors are raised.

Returns

Return type

List of subsections TestFunctions.

order(*subsections)
class pyats.aetest.discovery.ScriptDiscovery(target)

Bases: pyats.aetest.discovery.BaseDiscovery

Default discovery class for aetest test scripts, finds and orders the Testcases

discover()

discovery of test script sections

This api looks within the module contained in this TestScript class, and returns a list of those sections (classes), in their order of execution.

Discovery is based on classs, eg, test script may contain CommonSetup, Testcases and CommonCleanups.

Returns

1 value

Return type

ordered test script sections

order(setup=None, testcases=[], cleanup=None)

Puts testcases in order

Parameters
  • setup (-) – common_setup section

  • testcases (-) – list of testcases

  • cleanup (-) – common_cleanup section

Returns

Creates order for all 3 parameters provided above and returns a single list

class pyats.aetest.discovery.TestcaseDiscovery(target)

Bases: pyats.aetest.discovery.BaseTestDiscovery

Default discovery class for aetest test cases, finds and orders the tests

discover()

Testcase discovery

Main api to be called when it is turn to discover what’s defined within a testcase. Basically discovers any methods decorated with @setup, @test and @cleanup (or, has __testcls__ attribute tagged).

Returns

Return type

List of test sections (TestFunctions)

order(setup=None, tests=[], cleanup=None)

Puts test sections in order

Parameters
  • setup (-) – common_setup section

  • tests (-) – list of testcases

  • cleanup (-) – common_cleanup section

Returns

Creates order for all 3 parameters provided above and returns a single list

exception pyats.aetest.exceptions.AEtestExceptions

Bases: Exception

base class

exception pyats.aetest.exceptions.DatafileError

Bases: pyats.aetest.exceptions.AEtestExceptions

Raised when there’s an issue loading the datafile

exception pyats.aetest.exceptions.InvalidContextError

Bases: pyats.aetest.exceptions.AEtestExceptions

Errors for contexts in the wrong place e.g. Testcase in Common sections

exception pyats.aetest.exceptions.MultiSectionError

Bases: pyats.aetest.exceptions.AEtestExceptions

Errors the max number of allowed sections is exceeded e.g. only 1 setup

exception pyats.aetest.exceptions.SequenceError

Bases: pyats.aetest.exceptions.AEtestExceptions

Error when something in the sequence is not defined in the test container

exception pyats.aetest.exceptions.StepDebugFileLoadError

Bases: pyats.aetest.exceptions.AEtestExceptions

Raised when an error occurs while loading Yaml config file

class pyats.aetest.loop.DefaultLooper(uids=None, *, loopee=None, args=None, argvs=None, filler=None, **kwargs)

Bases: object

Default Loop Generation Class

The default loop generation iterator that generates testable Iterations.

  • provide new uids for each iteration

  • default uids to number generator

  • provide fixed argument/values input

  • provides kwargs argument/values input

  • auto-fills missing loop argument positions

  • last-minute generation of iteration (yield)

Behaviors:

  • missing argument positions will be filled with filler, regardless of if it’s kwargs mismatching or argvs mismatching

  • if user provided UIDs, then it doesn’t matter how many argument values are provided, the iterations end when we run out of uids

  • if using default uid generation, the loop ends when we exhaust all arguments

Example

>>> iterations = DefaultLooper(a = [1, 2, 3]
>>> iterations = DefaultLooper(args = ['a'], argvs = ((1,), (2,), (3,)))

DefaultLooper __init__

Instanciates the loop iterable. In typical user scripts, this API is instantiated when the module (script) is loaded.

Parameters
  • (iterable/callable) (argvs) – sequence of unique iteration UIDs. Defaults to a counter starting from 1 and auto-increment by 1 per iteration.

  • (obj) (filler) – uid default prefix when uids str not provided. if not provided, defaults to prefix “iteration”

  • (iterable/callable) – sequence) of arguments for each iteration

  • (iterable/callable) – sequence) of argument values for each iteration, each matching in position to args above.

  • (obj) – argument value positions. Default to None

  • (kwargs) (kwargs) – that is added to the list of argvs

Examples

# iteration with 2 arguments and 3 sets of iterations >>> DefaultLooper(args = (‘a’, ‘b’), argvs = ((1,2), (2,3)))

# iteration with 1 kwarg and 2 iterations >>> DefaultLooper(a = [1,2])

# iteration with custom uids iterating 3 times >>> DefaultLooper(uids = [‘a’, ‘b’, ‘c’])

static uid_generator(prefix, parameters)

Loop uid generator

Default loop uid generator, used when a loop iteration uid was not given implicitly. The generated uid format is:

<loopee name>[arg_a=value_a,arg_b=value_b,…]

where the loopee name is the function/class name.

Parameters
  • (string) (prefix) –

  • (dict) (parameters) –

Examples

Tc_one[a=3]

test[b=7] test[b=8] test[b=9]

class pyats.aetest.loop.Iteration(uid, parameters)

Bases: tuple

Create new instance of Iteration(uid, parameters)

property parameters

Alias for field number 1

property uid

Alias for field number 0

class pyats.aetest.loop.LoopDecorator(*args, generator=<class 'pyats.aetest.loop.DefaultLooper'>, **kwargs)

Bases: object

AEtest testable loop decorator

Defines & uses the AEtest loopable protocol that enables testable (section, Testcase etc) looping. This API is the decorator called within the user script that marks the testable to be looped during execution.

Note that this class is not used directly. Rather, users should be calling the @loop decorator instead (set below)

Loop Protocol:

  • testables with attr __loop__ (and is an iterable) is loopable

  • __loop__ obj should return Iteration objects when iterated, and contains:

    • uid: the uid of the loop iteration

    • kwargs: dict of key-value mapping that are called as funcargs for

      the looping testable

Example

>>> @aetest.loop(uids = [1, 2])
... class Testcase(aetest.Testcase):
...     pass
>>> @aetest.loop(loop_value = ['a', 'b', 'c'])
... class Testcase(aetest.Testcase):
...     pass

loop __init__

Parameters
  • (obj) (generator) –

  • (obj)DefaultLooper. using this argument enables users to supply a custom Iteration generator

  • (kwargs) (kwargs) –

classmethod mark(obj, *args, **kwargs)

mark for loops

classmethod of LoopDecorator. Used within testscript sections to enable post-mortem looping, eg. to mark a testcase or a section that occurs after this current section for looping. This is different from typical @loop decorator looking, in the sense that it allows users to configure testcase/section looping dynamically.

Example

>>> class CommonSetup(aetest.CommonSetup):
...     @aetest.subsection
...     def subsection(self):
...         aetest.loop.mark(Testcase, uids = [1,2,3])
...
>>> class Testcase(aetest.Testcase):
...     pass
Parameters
  • (object) (obj) –

  • (list args) (args) –

  • (kwargs) (kwargs) –

Returns

Return type

None

pyats.aetest.loop.get_iterations(obj)

returns an iterator/generator of test iterations currently defined for the given object.

Parameters

(obj) (obj) –

Returns

Return type

iterator/generator of iterations

pyats.aetest.loop.loop

alias of pyats.aetest.loop.LoopDecorator

pyats.aetest.loop.loopable(obj)

determines whether a test object is loopable based on the aetest looping protocol.

Parameters

(obj) (obj) –

Returns

Return type

True if object is loopable, False otherwise.

class pyats.aetest.main.AEtest(commandline=False, parser=None, legacy_cli=True)

Bases: object

Built-in __init__

Initializes AEtest object with default values required for the parser.

Parameters
  • (bool) (legacy_cli) –

  • (argparse.ArgumentParser) (parser) –

  • (bool)

configure_logging()

configure logging Configure logging level based on the values from CLI args parsing and values passed to the method.

configure_parser(commandline, parser, legacy)

configure cli parser

configure and returns a parser that can parse sys.argv. This api takes care of two things:

  1. parse sys.args passed from upstream (easypy), where any arguments not parsed by easypy or the job file is passed-through to aetest and the script, and

  2. parse sys.argv when executing in command-line mode (outside of easypy environment)

Parameters
  • (argparse.ArgumentParser) (parser) –

  • (bool) (legacy) –

parse_args(argv=None)

Parse sys.argv Parse the arguments present in sys.argv After parsing the known arguments remove them from sys.argv and keep the rest. Pay attention to always keep the testable program

Returns

Return type

dictionary of argument name/value where value is not None

run(testable, uid=None, reporter=None, uids=None, groups=None, pdb=False, step_debug=None, loglevel=0, random=False, random_seed=None, max_failures=None, pause_on=None, datafile=None, processors=None, **script_args)

run test engine

main API that runs a given testable. A testable can be a python AEtest script file, a script module (pre-loaded), or a pre-loaded module name.

Parameters
  • (obj) (testable) – or a module name.

  • (TestableId) (uid) –

  • (BaseRootReporter) (reporter) – the BaseRootReporter class.

  • (callable) (groups) – if that section is to be run

  • (callable) – test if that section is to be run

  • (bool) (random) –

  • (dict) (processors) –

  • (level) (loglevel) –

  • (bool) – in random order.

  • (int) (max_failures) – testcases. Use this to repeat a previously randomized run.

  • (int) – aborting script run

  • (script_args) (script_args) – be passed to script level as script args.

  • (string) (datafile) – format that holds phrases, testcases, stopper type and timeout values

  • (string) – script/testcase section data & features

  • (dict)

pyats.aetest.main.main(testable='__main__', **kwargs)

Shortcut call to run AEtest Main Program

This is needed in order to stay compatible for test scripts to run as a standalone script without using the __main__ functionality.

It simply wraps AEtest class to run with module name ‘__main__’, and exit.

Parameters

(dict) (kwargs) – to AEtest.runTests function.

Example

>>> if __name__ == '__main__':
...     aetest.main()
class pyats.aetest.parameters.Parameter(function, **kwargs)

Bases: object

Parameter class

internal object, used to stored the parametrized callable objects (such as functions and classes) defined in the user test script module. This class stores the original call argument for each parameter, and as well allows future extensions to support parameter auto-scoping, etc.

built-in __init__

stores a proxy of the callable object (for later evaluations)

Parameters
  • (callable) (func) – as a test input parameter

  • (dict) (kwargs) – callable

class pyats.aetest.parameters.ParameterDict(*args, **kwargs)

Bases: collections.UserDict

Parameters Dictionary

Subclass of python UserDict, similar to dict(), enabling the infra to carry an internal dictionary that stores the current internal/special parameters such as a reference to the testscript/testcase/section object in the current scope.

built-in __init__

initializes the class. Also adds self.internal to the obj so that internal parameters can be tracked.

copy()

built-in copy

same as the dict.copy() api, except also creates a copy of internal.

update(*args, **kwargs)

built-in update

same as the dict.update() api. additionally also updates the internal dictionary with the given object, if it is also a ParameterDict

class pyats.aetest.parameters.ParameterMap(*maps)

Bases: collections.ChainMap

Parameters Map

Subclass of python3 collections.ChainMap, enabling the infrastructure to chain together parent/child ParameterDict into a ChainMap style relationship.

built-in __init__

initializes the ParmaeterMap class. Also adds self.internal to the obj so that internal parameters can be tracked.

Note that we do not typecast maps argument: always use this with ParameterDict argument.

property local

the first parameter map item is always the local parameter

new_child(m=None)

built-in new_child

same as the ChainMap.new_child() api, except also creates a new child of internal.

update(*args, **kwargs)

built-in update

same as the dict.update() api. additionally also updates the internal dictionary with the given object, if it is also a ParameterMap

pyats.aetest.parameters.discover_parameters(obj)

discover parameters

checks all attributes of a given object and return a dictionary of parameter list/parameter object based on whether its attributes were parametrized. This api is mostly intended to be called on the script module object to discover script-level parameters.

Parameters

(object) (obj) –

Returns

Return type

dict() of name/parameter object

pyats.aetest.parameters.parametrize(target=None, **kwargs)

Parametrize decorator

Decorator used within test script to mark a function/class to be useable as as parameter within test script section. A marked function will have its Parameter class stored under __parameter__ attribute, but otherwise unchanged.

Parameters
  • (obj) (target) –

  • (kwargs) (kwargs) – the parameter object

Returns

Return type

target function, marked with __parameter__

Examples

>>> @parametrize
>>> def simpleParam():
...     pass
>>> @parametrize(a=1, b=2)
>>> def argParam(a, b):
...     return a+b
pyats.aetest.parameters.parametrized(obj)

parametrization check

API to return whether a given object has been parametrized (eg, has the __parameter__ attribute).

Parameters

(object) (obj) –

Returns

Return type

True/False

class pyats.aetest.script.TestScript(module, uid=None, reporter=None)

Bases: pyats.aetest.base.TestItem

TestScript class

Class that wraps a test script module. A test script in python is just a python module (type.ModuleType). This is not an extension of the module type. Rather, it’s a class wraps the module and provides additional functionality (such as test parametrization).

Note

technically a TestScript class should inherit from TestContainer since it really is a container. However, there are practical differences between the two, such as a TestContainer being indirectly inherited by the user, and TestScript being totally transparent to the user, etc. Thus, this class inherit from the base TestItem instead.

built-in __init__

instantiates the TestScript class with a module (the test script module) and looks into the module to see if there are any parameters to be discovered.

Parameters
  • (type.ModuleType) (module) –

  • (BaseRootReporter) (reporter) – reporter for TestScript

apply_data(data)

Applies the content of a dictionary (data) recursively into the currently loaded module. The data needs to follow a specific structure (as outlined by datafile/schema).

This API patches all live classes (Common*/Testcase classes etc), and leverages TestItem.apply_data() api to work.

Parameters

(dict) (data) –

classmethod from_source(testable, uid=None, reporter=None)

classmethod from_source

API to load user supplied testable to a TestScript class allowing the testable TestScript to be run directly.

Parameters
  • (obj) (testable) – of a loaded module, or an absolute module path

  • (str) (uid) –

  • (BaseRootReporter) (reporter) – reporter for TestScript

Returns

Return type

TestScript() class instantiated.

load_datafile(datafile)

Loads the content of input datafile into dictionary, and apply to to the module & its objects.

Note: this could have been implemented using recursive object attribute updates. However, that approach would yield very non-user-friendly exceptions, hence putting it down straight as loop-in-loop.

>>> for k, v in content.items():
...     if k == 'parameters':
...     # parameters must be updated instead of overwritte
...     # __parameters__ is the internal attribute
...     obj.__parameters__.update(content['parameters'])
...
...     elif isinstance(v, Mapping):
...         recur_testitem_update(getattr(obj, k), v)
...     else:
...         setattr(obj, k, v)
...
... return obj
Parameters

(str) (datafile) –

randomize(flag, seed=None)

enable/disable randomization of testcase run sequence. This internally instantiates a random.Random generator using the provided seed. If no seed was provided, a random seed between 0 and sys.maxsize is generated as the seed.

Parameters
  • (bool) (flag) –

  • (int) (seed) –

class pyats.aetest.sections.CleanupSection(function, uid=None, *args, **kwargs)

Bases: pyats.aetest.sections.TestcaseSection

CleanupSection class

Testcase cleanup section. Wrapper class for @cleanup marked Testcase function/method. Normally not seen/used directly by the user.

built-in __init__

Initializes the TestFunction by storing the given function (obj method)

Parameters
  • (function) (function) –

  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

class pyats.aetest.sections.SetupSection(function, uid=None, *args, **kwargs)

Bases: pyats.aetest.sections.TestcaseSection

SetupSection class

Testcase setup section. Wrapper class for @setup marked Testcase function/method. Normally not seen/used directly by the user.

built-in __init__

Initializes the TestFunction by storing the given function (obj method)

Parameters
  • (function) (function) –

  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

class pyats.aetest.sections.Subsection(function, uid=None, *args, **kwargs)

Bases: pyats.aetest.function.TestFunction

Subsection class

Extends TestFunction class to support the @subsections decorator. This class wraps each subsection (Common section method/functions) into a class object, enabling the infrastructure to track results, parameters & etc.

Note

this class is normally not used/seen by the user script.

built-in __init__

Initializes the TestFunction by storing the given function (obj method)

Parameters
  • (function) (function) –

  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

class pyats.aetest.sections.TestSection(function, uid=None, *args, **kwargs)

Bases: pyats.aetest.sections.TestcaseSection

TestSection class

Testcase test sections. Wrapper class for @test marked Testcase function/methods. Normally not seen directly by the user. This class serves no purpose other than to make TestSections a unique class.

built-in __init__

Initializes the TestFunction by storing the given function (obj method)

Parameters
  • (function) (function) –

  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

class pyats.aetest.sections.TestcaseSection(function, uid=None, *args, **kwargs)

Bases: pyats.aetest.function.TestFunction

TestcaseSection class

Base class that represents each Testcase section (such setup/test/cleanup). Only used to aggregate common functionality/code.

Note

this class is normally not used/seen by the user script.

built-in __init__

Initializes the TestFunction by storing the given function (obj method)

Parameters
  • (function) (function) –

  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

pyats.aetest.sections.cleanup(function=None, class_=<class 'pyats.aetest.sections.CleanupSection'>)

cleanup decorator

Decorator used to mark a Testcase section class method as its cleanup. Each Testcase may only have a single cleanup section, which removes all the env changes (configurations) left behind by the testcase.

Note that cleanup section cannot be looped

Parameters
  • (function) (function) –

  • (class) (class) – allows users to supply a subclass of the default class, changing the default behavior. Default: SetupSection

Returns

Return type

original function, marked.

Example

>>> class Testcase(aetest.Testcase):
...     @aetest.cleanup
...     def simple_cleanup(self):
...         pass
pyats.aetest.sections.setup(function=None, class_=<class 'pyats.aetest.sections.SetupSection'>)

setup decorator

Decorator used to mark a Testcase section class method as its setup. Each Testcase may only have a single setup section, which performs all the necessary configurations/checks required to run this Testcase. If a setup section is failed for a Testcase, the Testcase will not run. Note that setup section cannot be looped

Parameters
  • (function) (function) –

  • (class) (class) – allows users to supply a subclass of the default class, changing the default behavior. Default: SetupSection

Returns

Return type

original function, marked.

Example

>>> class Testcase(aetest.Testcase):
...     @aetest.setup
...     def simple_setup(self):
...         pass
pyats.aetest.sections.subsection(function=None, class_=<class 'pyats.aetest.sections.Subsection'>)

subsection decorator

Decorator used to mark a Common section class method as a subsection. Each subsection is a smaller breakdown/action step of its parent common section, where the final result of the common section is a combined roll up of all of its subsections.

Parameters
  • (function) (function) –

  • (class) (class) – allows users to supply a subclass of the default class, changing the default behavior. Default: Subsection

Returns

Return type

original function, marked.

Example

>>> class ExampleCommonSetup(aetest.CommonSetup):
...     @aetest.subsection
...     def simple_subsection(self):
...         pass
pyats.aetest.sections.subsection_loop(function=None, class_=<class 'pyats.aetest.sections.Subsection'>, **kwargs)

subsection loop decorator

Decorator used to mark a Common section class method as a subsection, and also loop that subsection using the given arguments. This is the exact same as subsection decorator, with the addtional support of also marking this subsection for looping in one shot. This is intended to make the user’s life easier and make the script look cleaner.

Parameters
  • (function) (function) –

  • (class) (class) – allows users to supply a subclass of the default class, changing the default behavior. Default: Subsection

  • (kwargs) (kwargs) –

Returns

Return type

original function, marked.

Example

>>> class ExampleCommonSetup(aetest.CommonSetup):
...     @aetest.subsection.loop(ids = ('id_one', 'id_two'))
...     def looped_subsection(self):
...         pass
pyats.aetest.sections.test(function=None, class_=<class 'pyats.aetest.sections.TestSection'>)

test decorator

Decorator used to mark a Testcase’s test section. Each testcase may have one or more test sections. A test section performs, ideally, a single test of a single type, so that the combined result of a Testcase is the aggregate result of all its tests.

Parameters
  • (function) (function) –

  • (class) (class) – allows users to supply a subclass of the default class, changing the default behavior. Default: Subsection

Returns

Return type

original function, marked.

Example

>>> class Testcase(aetest.Testcase):
...     @aetest.test
...     def simple_test(self):
...         pass
pyats.aetest.sections.test_loop(function=None, class_=<class 'pyats.aetest.sections.TestSection'>, **kwargs)

test loop decorator

Decorator used to mark a Testcase’s test section, and also loop that test section using the given arguments. This is the exact same as the test decorator, with the addtional support of also marking this test for looping in one shot. This is intended to make the user’s life easier and make the script look cleaner.

Parameters
  • (function) (function) –

  • (class) (class) – allows users to supply a subclass of the default class, changing the default behavior. Default: Subsection

  • (kwargs) (kwargs) –

Returns

Return type

original function, marked.

Example

>>> class Testcase(aetest.Testcase):
...     @aetest.test.loop(ids = ('id_one', 'id_two'))
...     def looped_test(self):
...         pass
exception pyats.aetest.signals.AEtestAbortedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Aborted
exception pyats.aetest.signals.AEtestBlockedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Blocked
exception pyats.aetest.signals.AEtestErroredSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Errored
exception pyats.aetest.signals.AEtestFailedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Failed
exception pyats.aetest.signals.AEtestInternalSignals

Bases: BaseException

Internal Signals class

The intention of this class is to subclass from BaseException and create a new exception to be used internally for signaling purposes. These are not exceptions in the sense that something “errored”, but more used for the fact that raising exceptions causes the code to terminate and return, so that we can collect immediate results.

Note that this is subclassing BaseException for the purpose of not being caught when try…except Exception is written in the script.

exception pyats.aetest.signals.AEtestPassedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Passed
exception pyats.aetest.signals.AEtestPassxSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Passx
exception pyats.aetest.signals.AEtestSkippedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

result = Skipped
exception pyats.aetest.signals.AEtestStepAbortedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Aborted
exception pyats.aetest.signals.AEtestStepBlockedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Blocked
exception pyats.aetest.signals.AEtestStepErroredSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Errored
exception pyats.aetest.signals.AEtestStepFailedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Failed
exception pyats.aetest.signals.AEtestStepPassedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Passed
exception pyats.aetest.signals.AEtestStepPassxSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Passx
exception pyats.aetest.signals.AEtestStepSkippedSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.StepSignal

result = Skipped
exception pyats.aetest.signals.ResultSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.AEtestInternalSignals

Subclassing AEtestInternalSignals, intended only to be used for signaling immediate results to the executer.

post_mortem()

post mortem debug the result signal

uses pdb.post_mortem to debug the location where the current signal is raised. Does nothing if the current signal result is not Errored or Failed.

Note

this is a customized code from pdb.post_mortem() and Pdb.interact(), basically skipping the current result signal frame and going back into the user script frame.

property result
exception pyats.aetest.signals.StepSignal(reason=None, goto=None, from_exception=None, data=None)

Bases: pyats.aetest.signals.ResultSignal

exception pyats.aetest.signals.TerminateStepSignal

Bases: pyats.aetest.signals.AEtestInternalSignals

Used to signal step termination to executer engine. Do not use for other purposes.

class pyats.aetest.testcase.Testcase(*args, **kwargs)

Bases: pyats.aetest.container.TestContainer

Testcase class

Testcases are the main container/collection of smaller tests. Each script must contain one or more testcases which carries out the heavy-lifting w.r.t actually performing the testing. Each testcase is further broken down into a single setup section, a cleanup section, and multiple tests. This class is intended to be subclassed (inherited) within the user test script for each individual testcase.

Example

>>> class MyTestcase(aetest.Testcase):
...     @aetest.setup
...     def setup(self):
...         pass
...
...     @aetest.test
...     def test(self):
...         pass
...
...     @aetest.cleanup
...     def cleanup(self):
...         pass

built in __init__

Initializes a TestContainer class by finding out the class id definition & passing it upstream to parent TestItem.__init__.

Parameters
  • (str) (uid) –

  • args/kwargs (arguments passed to parent TestItem.__init__) –

source = <pyats.aetest.base.Source object>