11import logging
2- import os
32from collections import defaultdict
43from datetime import UTC , datetime , timedelta
54from functools import partial
2423from testgen .common .models .table_group import TableGroup
2524from testgen .common .models .test_run import TestRun
2625from testgen .common .models .test_suite import TestSuite
27- from testgen .utils import get_exception_message
2826
2927from .run_refresh_data_chars import run_data_chars_refresh
3028from .run_test_validation import run_test_validation
@@ -52,12 +50,10 @@ def run_test_execution(
5250
5351 LOG .info ("Creating test run record" )
5452 test_run = TestRun (
53+ id = job_context .get ().job_id ,
5554 test_suite_id = test_suite_id ,
5655 test_starttime = datetime .now (UTC ) + time_delta ,
57- process_id = os .getpid (),
5856 )
59- if job_id := job_context .get ().job_id :
60- test_run .job_execution_id = job_id
6157
6258 # This runs in a subprocess — commit after every save so progress is visible
6359 # to the UI (separate session) and to execute_db_queries (independent connection).
@@ -134,22 +130,12 @@ def run_test_execution(
134130 # Refresh needed because previous query updates the test run too
135131 test_run .refresh ()
136132
137- except Exception as e :
133+ except Exception :
138134 LOG .exception ("Test execution encountered an error." )
139- LOG .info ("Setting test run status to Error" )
140- test_run .log_message = get_exception_message (e )
141- test_run .test_endtime = datetime .now (UTC ) + time_delta
142- test_run .status = "Error"
143- test_run .save ()
144- session .commit ()
135+ end_time = datetime .now (UTC ) + time_delta
145136 raise
146137 else :
147- LOG .info ("Setting test run status to Completed" )
148- test_run .test_endtime = datetime .now (UTC ) + time_delta
149- test_run .status = "Complete"
150- test_run .save ()
151- session .commit ()
152-
138+ end_time = datetime .now (UTC ) + time_delta
153139 LOG .info ("Updating latest run for test suite" )
154140 test_suite .last_complete_test_run_id = test_run .id
155141 test_suite .save ()
@@ -167,7 +153,7 @@ def run_test_execution(
167153 username = username ,
168154 sql_flavor = connection .sql_flavor_code ,
169155 test_count = test_run .test_ct ,
170- run_duration = (test_run . test_endtime - test_run .test_starttime .replace (tzinfo = UTC )).total_seconds (),
156+ run_duration = (end_time - test_run .test_starttime .replace (tzinfo = UTC )).total_seconds (),
171157 prediction_duration = (datetime .now (UTC ) + time_delta - prediction_start ).total_seconds (),
172158 )
173159
0 commit comments