| 173 | |
| 174 | |
| 175 | def run_test(test, global_variables, connection, binary): |
| 176 | variables = global_variables.copy() |
| 177 | variables.update(test.get('variables', {})) |
| 178 | |
| 179 | cursor = connection.cursor(binary=binary) |
| 180 | |
| 181 | test_failed = False |
| 182 | try: |
| 183 | # Prepare phase |
| 184 | prepare_steps = test.get('prepare', []) |
| 185 | execute_steps(prepare_steps, variables, cursor, connection) |
| 186 | |
| 187 | # Test steps |
| 188 | test_steps = test.get('steps', []) |
| 189 | execute_steps(test_steps, variables, cursor, connection) |
| 190 | |
| 191 | print(f"Test '{test['name']}' passed.") |
| 192 | |
| 193 | test_failed = False |
| 194 | |
| 195 | except Exception as e: |
| 196 | print(f"Test '{test['name']}' failed: {str(e)}") |
| 197 | test_failed = True |
| 198 | |
| 199 | finally: |
| 200 | # Teardown phase should run regardless of test outcome |
| 201 | teardown_steps = test.get('teardown', []) |
| 202 | try: |
| 203 | execute_steps(teardown_steps, variables, cursor, connection) |
| 204 | except Exception as teardown_exception: |
| 205 | print(f"Teardown for test '{test['name']}' failed: {str(teardown_exception)}") |
| 206 | cursor.close() |
| 207 | if test_failed: |
| 208 | sys.exit(1) |
| 209 | |
| 210 | |
| 211 | def main(yaml_file): |