{"id":7537,"library":"pyats-aetest","title":"pyATS AEtest","description":"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.","status":"active","version":"26.3","language":"en","source_language":"en","source_url":"https://github.com/Cisco-pyATS/pyATS.aetest","tags":["testing","network-automation","cisco","devnet"],"install":[{"cmd":"pip install pyats.aetest","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The PyPI package `pyats-aetest` is imported as `pyats.aetest` or directly from `pyats` as `aetest`.","wrong":"import pyats_aetest","symbol":"aetest","correct":"from pyats import aetest"}],"quickstart":{"code":"from pyats import aetest\n\nclass CommonSetup(aetest.CommonSetup):\n    \"\"\"Common Setup for all testcases\"\"\"\n    @aetest.subsection\n    def initial_setup(self):\n        self.parent.parameters['my_data'] = 'initialized_data'\n        self.passed('Common Setup completed')\n\nclass TestcaseOne(aetest.Testcase):\n    \"\"\"A simple testcase\"\"\"\n    @aetest.test\n    def check_data(self):\n        data = self.parent.parameters.get('my_data')\n        if data == 'initialized_data':\n            self.passed(f'Data matched: {data}')\n        else:\n            self.failed(f'Unexpected data: {data}')\n\nclass CommonCleanup(aetest.CommonCleanup):\n    \"\"\"Common Cleanup for all testcases\"\"\"\n    @aetest.subsection\n    def final_cleanup(self):\n        self.passed('Common Cleanup completed')\n\nif __name__ == '__main__':\n    # To run this script:\n    # 1. Save it as e.g., my_test.py\n    # 2. Execute: python my_test.py\n    # For advanced features like testbed parsing, use 'pyats run testbed my_test.py'\n    aetest.main()","lang":"python","description":"This quickstart demonstrates the basic structure of a pyATS AEtest script, including `CommonSetup`, `Testcase`, and `CommonCleanup` sections. It defines a simple testcase that uses data set up in the CommonSetup. The `aetest.main()` call allows the script to be executed directly."},"warnings":[{"fix":"Ensure your environment uses Python 3.8 or a later supported version. Upgrade Python if necessary or use a virtual environment with the correct Python version.","message":"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.","severity":"breaking","affected_versions":"< 24.x"},{"fix":"Always use `from pyats import aetest` or `import pyats.aetest` in your code. Install with `pip install pyats.aetest`.","message":"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`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For full functionality, including testbed parsing and rich reporting, always run your AEtest scripts using the `pyats run testbed` command: `pyats run testbed <script.py> --testbed-file <testbed.yaml>`.","message":"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']`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer `self.runtime.testbed` for accessing the testbed object within your test sections, ensuring your script is executed via `pyats run testbed`.","message":"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`.","severity":"deprecated","affected_versions":"Pre-24.x (still functional but less robust)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure installation with `pip install pyats.aetest` and import using `from pyats import aetest` or `import 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`.","error":"ModuleNotFoundError: No module named 'pyats_aetest'"},{"fix":"Run your test script using the `pyats run testbed` command, specifying a testbed file: `pyats run testbed <script.py> --testbed-file <testbed.yaml>`.","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.","error":"AttributeError: 'Runtime' object has no attribute 'testbed'"},{"fix":"Carefully 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.","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.","error":"TypeError: 'str' object is not callable when trying to execute a test section"}]}