Try ERPNext Buy Support Partners Foundation

Before_tests function

I have this code for pass first run wizard proccess. For my tests necessary to have some Item Groups, because I generate Sales Invoices and Items. I have this part of code, that has been stolen from erpnext.setup.utils.before_tests
When I execute this function first time - nothing happens. But when I do it twice - all is work. Can you give me explanation, why?

def before_tests():
frappe.clear_cache()
# complete setup if missing
from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
if not frappe.get_list("Company"):
    setup_complete({
        "currency": "USD",
        "full_name" :"Test User",
        "company_name" :"Wind Power LLC",
        "timezone"		:"America/New_York",
        "company_abbr"		:"WP",
        "industry"			:"Manufacturing",
        "country"			:"United States",
        "fy_start_date"		:"2020-01-01",
        "fy_end_date"		:"2020-12-31",
        "language"			:"english",
        "company_tagl"	:"Testing",
        "email"				:"test@erpnext.com",
        "password"			:"test",
        "chart_of_accou" : "Standard",
        "domains"			: ["Manufacturing"],
    })

frappe.db.sql("delete from `tabLeave Allocation`")
frappe.db.sql("delete from `tabLeave Application`")
frappe.db.sql("delete from `tabSalary Slip`")
frappe.db.sql("delete from `tabItem Price`")

frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 0)
enable_all_roles_and_domains()
frappe.db.commit()