| 96 | |
| 97 | |
| 98 | def run_test(test, global_variables, connection): |
| 99 | variables = global_variables.copy() |
| 100 | variables.update(test.get('variables', {})) |
| 101 | |
| 102 | cursor = connection.cursor() |
| 103 | |
| 104 | try: |
| 105 | # Prepare phase |
| 106 | prepare_steps = test.get('prepare', []) |
| 107 | execute_steps(prepare_steps, variables, cursor, connection) |
| 108 | |
| 109 | # Test steps |
| 110 | test_steps = test.get('steps', []) |
| 111 | execute_steps(test_steps, variables, cursor, connection) |
| 112 | |
| 113 | print(f"Test '{test['name']}' passed.") |
| 114 | |
| 115 | test_failed = False |
| 116 | |
| 117 | except Exception as e: |
| 118 | print(f"Test '{test['name']}' failed: {str(e)}") |
| 119 | test_failed = True |
| 120 | |
| 121 | finally: |
| 122 | # Teardown phase should run regardless of test outcome |
| 123 | teardown_steps = test.get('teardown', []) |
| 124 | try: |
| 125 | execute_steps(teardown_steps, variables, cursor, connection) |
| 126 | except Exception as teardown_exception: |
| 127 | print(f"Teardown for test '{test['name']}' failed: {str(teardown_exception)}") |
| 128 | # Optionally handle teardown exceptions (e.g., logging) |
| 129 | cursor.close() |
| 130 | if test_failed: |
| 131 | sys.exit(1) |
| 132 | |
| 133 | |
| 134 | def main(yaml_file): |