MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / save_test_failure_data

Function save_test_failure_data

seleniumbase/core/report_helper.py:34–96  ·  view source on GitHub ↗

Saves failure data to the current directory, or to a subfolder if provided. If {name} does not end in ".txt", it will get added to it. If the folder provided doesn't exist, it will get created.

(test, name, folder=None)

Source from the content-addressed store, hash-verified

32
33
34def save_test_failure_data(test, name, folder=None):
35 """
36 Saves failure data to the current directory, or to a subfolder if provided.
37 If {name} does not end in ".txt", it will get added to it.
38 If the folder provided doesn't exist, it will get created.
39 """
40 if not name.endswith(".txt"):
41 name = name + ".txt"
42 if folder:
43 abs_path = os.path.abspath(".")
44 file_path = os.path.join(abs_path, folder)
45 if not os.path.exists(file_path):
46 os.makedirs(file_path)
47 failure_data_file_path = os.path.join(file_path, name)
48 else:
49 failure_data_file_path = name
50 failure_data_file = open(
51 failure_data_file_path, mode="w+", encoding="utf-8"
52 )
53 data_to_save = []
54 if not hasattr(sb_config, "_report_test_id"):
55 exc_message = "(Unknown Exception)"
56 traceback_message = ""
57 if hasattr(sb_config, "_report_traceback"):
58 traceback_message = str(sb_config._report_traceback)
59 if hasattr(sb_config, "_report_exception"):
60 if type(sb_config._report_exception) is tuple:
61 exc_message = str(sb_config._report_exception[1].message)
62 else:
63 exc_message = str(sb_config._report_exception)
64 data_to_save.append(test.id())
65 data_to_save.append(
66 "----------------------------------------------------------------"
67 )
68 data_to_save.append("Last Page: %s" % test._last_page_url)
69 data_to_save.append(" Browser: %s" % test.browser)
70 data_to_save.append("Timestamp: %s" % get_timestamp()[:-3])
71 data_to_save.append(
72 "----------------------------------------------------------------"
73 )
74 data_to_save.append("Traceback: %s" % traceback_message)
75 data_to_save.append("Exception: %s" % exc_message)
76 failure_data_file.writelines("\r\n".join(data_to_save))
77 failure_data_file.close()
78 return
79 data_to_save.append(sb_config._report_test_id)
80 data_to_save.append(
81 "--------------------------------------------------------------------"
82 )
83 data_to_save.append("Last Page: %s" % sb_config._report_fail_page)
84 data_to_save.append(" Duration: %s" % sb_config._report_duration)
85 data_to_save.append(" Browser: %s" % sb_config._report_browser)
86 data_to_save.append(" Driver: %s" % sb_config._report_driver)
87 data_to_save.append("Timestamp: %s" % sb_config._report_timestamp)
88 data_to_save.append(" Date: %s" % sb_config._report_date)
89 data_to_save.append(" Time: %s" % sb_config._report_time)
90 data_to_save.append(
91 "--------------------------------------------------------------------"

Callers 1

process_failuresFunction · 0.85

Calls 2

get_timestampFunction · 0.85
closeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…