pyATS AEtest
pyATS AEtest (version 26.3) is the primary test automation engine within the Cisco pyATS framework, designed for structured and hierarchical test script development, particularly for network device testing. It provides robust features such as common setup/cleanup stages, testcase parametrization, and comprehensive result reporting. The library typically follows a monthly or bi-monthly release cadence, aligning with broader pyATS framework updates.
Common errors
-
ModuleNotFoundError: No module named 'pyats_aetest'
cause The package was either not installed correctly using the dot notation, or the import statement used `_` instead of `.` or directly imported `pyats_aetest`.fixEnsure installation with `pip install pyats.aetest` and import using `from pyats import aetest` or `import pyats.aetest`. -
AttributeError: 'Runtime' object has no attribute 'testbed'
cause The test script is attempting to access `self.runtime.testbed` (or `self.parameters['testbed']`) but was executed directly via `python <script.py>` without a testbed being loaded by the pyATS infrastructure.fixRun your test script using the `pyats run testbed` command, specifying a testbed file: `pyats run testbed <script.py> --testbed-file <testbed.yaml>`. -
TypeError: 'str' object is not callable when trying to execute a test section
cause This often happens if you accidentally define a method like `@aetest.test def setup(self):` where `setup` is a string parameter for a decorator, or if you attempt to call a variable that holds a string.fixCarefully review your test section definitions, ensuring that `aetest.test`, `aetest.subsection`, etc., are applied to methods, and that method names don't conflict with built-in or reserved names if called directly as variables.
Warnings
- breaking pyATS AEtest officially supports Python 3.8 and newer. Attempting to use older Python versions (e.g., Python 2.7 or Python 3.7) will lead to compatibility issues and `SyntaxError` or `ImportError` messages.
- gotcha The PyPI package name `pyats-aetest` uses a hyphen, but the Python package name for importing is `pyats.aetest`. A common mistake is trying to `import pyats_aetest` or `import pyats-aetest`.
- gotcha Running an AEtest script directly (e.g., `python my_test.py`) will execute the tests, but it will not automatically parse a testbed YAML file or provide advanced reporting features. This can lead to `AttributeError` if your script tries to access `self.runtime.testbed` or `self.parameters['testbed']`.
- deprecated Older pyATS versions used `self.parent.parameters['testbed']` to access the testbed object. While this still works, the recommended and more robust way to access the testbed is via `self.runtime.testbed` when running with `pyats run testbed`.
Install
-
pip install pyats.aetest
Imports
- aetest
import pyats_aetest
from pyats import aetest
Quickstart
from pyats import aetest
class CommonSetup(aetest.CommonSetup):
"""Common Setup for all testcases"""
@aetest.subsection
def initial_setup(self):
self.parent.parameters['my_data'] = 'initialized_data'
self.passed('Common Setup completed')
class TestcaseOne(aetest.Testcase):
"""A simple testcase"""
@aetest.test
def check_data(self):
data = self.parent.parameters.get('my_data')
if data == 'initialized_data':
self.passed(f'Data matched: {data}')
else:
self.failed(f'Unexpected data: {data}')
class CommonCleanup(aetest.CommonCleanup):
"""Common Cleanup for all testcases"""
@aetest.subsection
def final_cleanup(self):
self.passed('Common Cleanup completed')
if __name__ == '__main__':
# To run this script:
# 1. Save it as e.g., my_test.py
# 2. Execute: python my_test.py
# For advanced features like testbed parsing, use 'pyats run testbed my_test.py'
aetest.main()