pyATS Results
pyATS Results is a core component of the Cisco pyATS framework, providing an object-oriented API for representing and managing test execution results such as Pass, Fail, Warn, Error, and others. It ensures consistent handling and reporting across various test scenarios within the pyATS ecosystem. As of version 26.3, it is actively maintained with frequent releases aligned with the broader pyATS framework, typically on a monthly cadence.
Common errors
-
ModuleNotFoundError: No module named 'pyats.results'
cause The `pyats-results` package or the broader `pyATS` framework is not installed in your Python environment.fixInstall the package using `pip install pyats-results` if you only need the results component, or `pip install pyats` to get the entire framework along with `pyats-results`. -
AttributeError: 'Result' object has no attribute 'status'
cause Attempting to access a `status` attribute on a `pyats.results.Result` object, which does not exist.fixUse `result.state` to get or set the result's state (e.g., 'Passed', 'Failed'). The `status` attribute is not part of the `pyats.results.Result` API. -
TypeError: Pass() missing 1 required positional argument: 'message'
cause While `Pass()`, `Fail()`, etc., can take an optional `message` argument, if a downstream custom class or an older version of the API expected a message, calling it without one could lead to this error. More commonly, trying to pass too many arguments or incorrect types.fixEnsure you are either calling the result class constructor with no arguments if you intend to set the message later (`result = Pass(); result.message = '...'`) or provide a single string message argument (`result = Pass('My test message')`). Consult the specific pyATS version's documentation for exact constructor signatures.
Warnings
- gotcha All pyATS core components (e.g., `pyats`, `pyats.topology`, `pyats.results`, `pyats.aereports`) must be installed with compatible versions. Mismatched versions, especially across major releases, can lead to subtle bugs or unexpected runtime errors due to internal API changes.
- gotcha The `state` attribute of `Result` objects is case-sensitive and expects specific string values (e.g., 'Passed', 'Failed', 'Warning', 'Aborted', 'Blocked', 'Errored', 'Skipped', 'PostProcessor'). Assigning non-standard or incorrectly cased strings can lead to issues with downstream reporting tools or integrations that rely on these predefined states.
Install
-
pip install pyats-results -
pip install pyats
Imports
- Result
from pyats.results import Result
- Pass
from pyats.results import Pass
- Fail
from pyats.results import Fail
- Warn
from pyats.results import Warn
- Error
from pyats.results import Error
Quickstart
from pyats.results import Pass, Fail, Result
def run_my_test_example():
# Example 1: Using specific result classes
test_case_status = True
if test_case_status:
result1 = Pass('Scenario A completed successfully.')
else:
result1 = Fail('Scenario A encountered a critical error.')
# Example 2: Using the base Result class and setting its state
result2 = Result()
result2.state = 'Blocked'
result2.message = 'Scenario B was blocked by a previous failure.'
# Example 3: Instantiating a warning
result3 = Result()
result3.state = 'Warning'
result3.message = 'Scenario C completed with minor warnings.'
print(f"Test 1: {result1.state} - {result1.message}")
print(f"Test 2: {result2.state} - {result2.message}")
print(f"Test 3: {result3.state} - {result3.message}")
# Assertions for quickstart validation
assert result1.state == 'Passed'
assert result2.state == 'Blocked'
assert result3.state == 'Warning'
if __name__ == "__main__":
run_my_test_example()