Merge pull request #48111 from sagarvora/use-frappe.in_test

This commit is contained in:
Sagar Vora
2025-06-20 08:24:27 +00:00
committed by GitHub
32 changed files with 51 additions and 48 deletions

View File

@@ -42,3 +42,6 @@ a308792ee7fda18a681e9181f4fd00b36385bc23
# noisy typing refactoring of get_item_details
7b7211ac79c248a79ba8a999ff34e734d874c0ae
d827ed21adc7b36047e247cbb0dc6388d048a7f9
# `frappe.flags.in_test` => `frappe.in_test`
7a482a69985c952de0e8193c9d4e086aee65ee6d

View File

@@ -57,7 +57,7 @@ def get_company_currency(company):
def set_perpetual_inventory(enable=1, company=None):
if not company:
company = "_Test Company" if frappe.flags.in_test else get_default_company()
company = "_Test Company" if frappe.in_test else get_default_company()
company = frappe.get_doc("Company", company)
company.enable_perpetual_inventory = enable
@@ -77,7 +77,7 @@ def encode_company_abbr(name, company=None, abbr=None):
def is_perpetual_inventory_enabled(company):
if not company:
company = "_Test Company" if frappe.flags.in_test else get_default_company()
company = "_Test Company" if frappe.in_test else get_default_company()
if not hasattr(frappe.local, "enable_perpetual_inventory"):
frappe.local.enable_perpetual_inventory = {}

View File

@@ -526,7 +526,7 @@ def make_gl_entries(
make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True)
frappe.db.commit()
except Exception as e:
if frappe.flags.in_test:
if frappe.in_test:
doc.log_error(f"Error while processing deferred accounting for Invoice {doc.name}")
raise e
else:

View File

@@ -602,7 +602,7 @@ def _ensure_idle_system():
# 1. Correctness: It's next to impossible to ensure that renamed account is not being used *right now*.
# 2. Performance: Renaming requires locking out many tables entirely and severely degrades performance.
if frappe.flags.in_test:
if frappe.in_test:
return
last_gl_update = None

View File

@@ -83,7 +83,7 @@ class AccountingDimension(Document):
frappe.throw(_("Company {0} is added more than once").format(frappe.bold(default.company)))
def after_insert(self):
if frappe.flags.in_test:
if frappe.in_test:
make_dimension_in_accounting_doctypes(doc=self)
else:
frappe.enqueue(
@@ -91,7 +91,7 @@ class AccountingDimension(Document):
)
def on_trash(self):
if frappe.flags.in_test:
if frappe.in_test:
delete_accounting_dimension(doc=self)
else:
frappe.enqueue(delete_accounting_dimension, doc=self, queue="long", enqueue_after_commit=True)
@@ -213,7 +213,7 @@ def delete_accounting_dimension(doc):
@frappe.whitelist()
def disable_dimension(doc):
if frappe.flags.in_test:
if frappe.in_test:
toggle_disabling(doc=doc)
else:
frappe.enqueue(toggle_disabling, doc=doc)

View File

@@ -79,7 +79,7 @@ class BankStatementImport(DataImport):
from frappe.utils.background_jobs import is_job_enqueued
from frappe.utils.scheduler import is_scheduler_inactive
run_now = frappe.flags.in_test or frappe.conf.developer_mode
run_now = frappe.in_test or frappe.conf.developer_mode
if is_scheduler_inactive() and not run_now:
frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive"))

View File

@@ -36,7 +36,7 @@ class CurrencyExchangeSettings(Document):
def validate(self):
self.set_parameters_and_result()
if frappe.flags.in_test or frappe.flags.in_install or frappe.flags.in_setup_wizard:
if frappe.in_test or frappe.flags.in_install or frappe.flags.in_setup_wizard:
return
response, value = self.validate_parameters()
self.validate_result(response, value)

View File

@@ -123,7 +123,7 @@ def check_duplicate_fiscal_year(doc):
)
for fiscal_year, ysd, yed in year_start_end_dates:
if (getdate(doc.year_start_date) == ysd and getdate(doc.year_end_date) == yed) and (
not frappe.flags.in_test
not frappe.in_test
):
frappe.throw(
_(

View File

@@ -35,7 +35,7 @@ class LedgerMerge(Document):
from frappe.utils.background_jobs import enqueue
from frappe.utils.scheduler import is_scheduler_inactive
if is_scheduler_inactive() and not frappe.flags.in_test:
if is_scheduler_inactive() and not frappe.in_test:
frappe.throw(_("Scheduler is inactive. Cannot merge accounts."), title=_("Scheduler Inactive"))
job_id = f"ledger_merge::{self.name}"
@@ -47,7 +47,7 @@ class LedgerMerge(Document):
event="ledger_merge",
job_id=job_id,
docname=self.name,
now=frappe.conf.developer_mode or frappe.flags.in_test,
now=frappe.conf.developer_mode or frappe.in_test,
)
return True

View File

@@ -229,7 +229,7 @@ class OpeningInvoiceCreationTool(Document):
else:
from frappe.utils.scheduler import is_scheduler_inactive
if is_scheduler_inactive() and not frappe.flags.in_test:
if is_scheduler_inactive() and not frappe.in_test:
frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive"))
job_id = f"opening_invoice::{self.name}"
@@ -242,7 +242,7 @@ class OpeningInvoiceCreationTool(Document):
event="opening_invoice_creation",
job_id=job_id,
invoices=invoices,
now=frappe.conf.developer_mode or frappe.flags.in_test,
now=frappe.conf.developer_mode or frappe.in_test,
)

View File

@@ -493,7 +493,7 @@ def split_invoices_by_accounting_dimension(pos_invoices):
def consolidate_pos_invoices(pos_invoices=None, closing_entry=None):
invoices = pos_invoices or (closing_entry and closing_entry.get("pos_invoices"))
if frappe.flags.in_test and not invoices:
if frappe.in_test and not invoices:
invoices = get_all_unconsolidated_invoices()
invoice_by_customer = get_invoice_customer_map(invoices)
@@ -655,7 +655,7 @@ def enqueue_job(job, **kwargs):
timeout=10000,
event="processing_merge_logs",
job_id=job_id,
now=frappe.conf.developer_mode or frappe.flags.in_test,
now=frappe.conf.developer_mode or frappe.in_test,
)
if job == create_merge_logs:
@@ -667,7 +667,7 @@ def enqueue_job(job, **kwargs):
def check_scheduler_status():
if is_scheduler_inactive() and not frappe.flags.in_test:
if is_scheduler_inactive() and not frappe.in_test:
frappe.throw(_("Scheduler is inactive. Cannot enqueue job."), title=_("Scheduler Inactive"))

View File

@@ -1480,7 +1480,7 @@ def repost_gle_for_stock_vouchers(
else:
_delete_accounting_ledger_entries(voucher_type, voucher_no)
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit()
if repost_doc:

View File

@@ -654,7 +654,7 @@ class AccountsController(TransactionBase):
self.base_paid_amount = 0
def set_missing_values(self, for_validate=False):
if frappe.flags.in_test:
if frappe.in_test:
for fieldname in ["posting_date", "transaction_date"]:
if self.meta.get_field(fieldname) and not self.get(fieldname):
self.set(fieldname, today())

View File

@@ -242,7 +242,7 @@ def enqueue_multiple_variant_creation(item, args, use_template_image=False):
item=item,
args=args,
use_template_image=use_template_image,
now=frappe.flags.in_test,
now=frappe.in_test,
)
return "queued"

View File

@@ -230,7 +230,7 @@ class StockController(AccountsController):
return
# To handle test cases
if frappe.flags.in_test and frappe.flags.use_serial_and_batch_fields:
if frappe.in_test and frappe.flags.use_serial_and_batch_fields:
return
if not table_name:

View File

@@ -11,7 +11,7 @@ def validate_webhooks_request(doctype, hmac_key, secret_key="secret"):
def innerfn(fn):
settings = frappe.get_doc(doctype)
if frappe.request and settings and settings.get(secret_key) and not frappe.flags.in_test:
if frappe.request and settings and settings.get(secret_key) and not frappe.in_test:
sig = base64.b64encode(
hmac.new(
settings.get(secret_key).encode("utf8"), frappe.request.data, hashlib.sha256

View File

@@ -1302,7 +1302,7 @@ def validate_bom_no(item, bom_no):
if not bom.is_active:
frappe.throw(_("BOM {0} must be active").format(bom_no))
if bom.docstatus != 1:
if not getattr(frappe.flags, "in_test", False):
if not frappe.in_test:
frappe.throw(_("BOM {0} must be submitted").format(bom_no))
if item:
rm_item_exists = False

View File

@@ -108,7 +108,7 @@ class BOMUpdateLog(Document):
doc=self,
boms=boms,
timeout=40000,
now=frappe.flags.in_test,
now=frappe.in_test,
enqueue_after_commit=True,
)
else:
@@ -116,7 +116,7 @@ class BOMUpdateLog(Document):
method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.process_boms_cost_level_wise",
queue="long",
update_doc=self,
now=frappe.flags.in_test,
now=frappe.in_test,
enqueue_after_commit=True,
)
@@ -128,7 +128,7 @@ def run_replace_bom_job(
try:
doc.db_set("status", "In Progress")
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit()
frappe.db.auto_commit_on_many_writes = 1
@@ -141,7 +141,7 @@ def run_replace_bom_job(
finally:
frappe.db.auto_commit_on_many_writes = 0
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit() # nosemgrep
@@ -203,7 +203,7 @@ def queue_bom_cost_jobs(current_boms_list: list[str], update_doc: "BOMUpdateLog"
bom_list=boms_to_process,
batch_name=batch_row.name,
queue="long",
now=frappe.flags.in_test,
now=frappe.in_test,
)

View File

@@ -63,7 +63,7 @@ def update_cost_in_level(doc: "BOMUpdateLog", bom_list: list[str], batch_name: i
except Exception:
handle_exception(doc)
finally:
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit() # nosemgrep
@@ -120,7 +120,7 @@ def update_cost_in_boms(bom_list: list[str]) -> None:
bom_doc.calculate_cost(save_updates=True, update_hour_rate=True)
bom_doc.db_update()
if (index % 50 == 0) and not frappe.flags.in_test:
if (index % 50 == 0) and not frappe.in_test:
frappe.db.commit() # nosemgrep
@@ -216,7 +216,7 @@ def set_values_in_log(log_name: str, values: dict[str, Any], commit: bool = Fals
query = query.set(key, value)
query.run()
if commit and not frappe.flags.in_test:
if commit and not frappe.in_test:
frappe.db.commit() # nosemgrep

View File

@@ -112,7 +112,7 @@ class Task(NestedSet):
)
def validate_parent_project_dates(self):
if not self.project or frappe.flags.in_test:
if not self.project or frappe.in_test:
return
if project_end_date := frappe.db.get_value("Project", self.project, "expected_end_date"):

View File

@@ -49,7 +49,7 @@ class VATAuditReport:
self.sa_vat_accounts = frappe.get_all(
"South Africa VAT Account", filters={"parent": self.filters.company}, pluck="account"
)
if not self.sa_vat_accounts and not frappe.flags.in_test and not frappe.flags.in_migrate:
if not self.sa_vat_accounts and not frappe.in_test and not frappe.flags.in_migrate:
link_to_settings = get_link_to_form(
"South Africa VAT Settings", "", label="South Africa VAT Settings"
)

View File

@@ -57,7 +57,7 @@ def get_tax_accounts(company):
tax_accounts_dict = frappe._dict()
tax_accounts_list = frappe.get_all("UAE VAT Account", filters={"parent": company}, fields=["Account"])
if not tax_accounts_list and not frappe.flags.in_test:
if not tax_accounts_list and not frappe.in_test:
frappe.throw(_('Please set Vat Accounts for Company: "{0}" in UAE VAT Settings').format(company))
for tax_account in tax_accounts_list:
for _account, name in tax_account.items():

View File

@@ -32,7 +32,7 @@ class ItemGroup(NestedSet):
# end: auto-generated types
def validate(self):
if not self.parent_item_group and not frappe.flags.in_test:
if not self.parent_item_group and not frappe.in_test:
if frappe.db.exists("Item Group", _("All Item Groups")):
self.parent_item_group = _("All Item Groups")
self.validate_item_group_defaults()

View File

@@ -22,7 +22,7 @@ def get_warehouse_account_map(company=None):
)
warehouse_account_map = frappe.flags.warehouse_account_map
if not warehouse_account_map or not company_warehouse_account_map or frappe.flags.in_test:
if not warehouse_account_map or not company_warehouse_account_map or frappe.in_test:
warehouse_account = frappe._dict()
filters = {}

View File

@@ -773,7 +773,7 @@ class Item(Document):
"erpnext.stock.doctype.item.item.update_variants",
variants=variants,
template=self,
now=frappe.flags.in_test,
now=frappe.in_test,
timeout=600,
enqueue_after_commit=True,
)

View File

@@ -195,7 +195,7 @@ class RepostItemValuation(Document):
These flags are useful for asserting real time behaviour like quantity updates.
"""
if not frappe.flags.in_test:
if not frappe.in_test:
return
if self.flags.dont_run_in_test or frappe.flags.dont_execute_stock_reposts:
return
@@ -276,7 +276,7 @@ def repost(doc):
frappe.db.MAX_WRITES_PER_TRANSACTION *= 4
doc.set_status("In Progress")
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit()
if doc.recreate_stock_ledgers:
@@ -290,7 +290,7 @@ def repost(doc):
remove_attached_file(doc.name)
except Exception as e:
if frappe.flags.in_test:
if frappe.in_test:
# Don't silently fail in tests,
# there is no reason for reposts to fail in CI
raise
@@ -329,7 +329,7 @@ def repost(doc):
notify_error_to_stock_managers(doc, message)
doc.set_status("Failed")
finally:
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit()

View File

@@ -115,7 +115,7 @@ class SerialandBatchBundle(Document):
return
self.allow_existing_serial_nos()
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
if not self.flags.ignore_validate_serial_batch or frappe.in_test:
self.validate_serial_nos_duplicate()
self.check_future_entries_exists()

View File

@@ -111,7 +111,7 @@ def make_stock_entry(**args):
args.company = frappe.db.get_value("Warehouse", args.target, "company")
# set vales from test
if frappe.flags.in_test:
if frappe.in_test:
if not args.company:
args.company = "_Test Company"
if not args.item:

View File

@@ -172,7 +172,7 @@ class StockLedgerEntry(Document):
self.check_stock_frozen_date()
# Added to handle few test cases where serial_and_batch_bundles are not required
if frappe.flags.in_test and frappe.flags.ignore_serial_batch_bundle_validation:
if frappe.in_test and frappe.flags.ignore_serial_batch_bundle_validation:
return
if not self.get("via_landed_cost_voucher"):

View File

@@ -145,7 +145,7 @@ class StockSettings(Document):
# changed to text
frappe.enqueue(
"erpnext.stock.doctype.stock_settings.stock_settings.clean_all_descriptions",
now=frappe.flags.in_test,
now=frappe.in_test,
enqueue_after_commit=True,
)
@@ -160,7 +160,7 @@ class StockSettings(Document):
self.auto_reserve_stock = 0
# Skip validation for tests
if frappe.flags.in_test:
if frappe.in_test:
return
# Change in value of `Allow Negative Stock`

View File

@@ -378,7 +378,7 @@ def update_args_in_repost_item_valuation(doc, index, args, distinct_item_warehou
}
)
if not frappe.flags.in_test:
if not frappe.in_test:
frappe.db.commit()
frappe.publish_realtime(

View File

@@ -131,7 +131,7 @@ class SubcontractingReceipt(SubcontractingController):
super().validate()
if self.is_new() and self.get("_action") == "save" and not frappe.flags.in_test:
if self.is_new() and self.get("_action") == "save" and not frappe.in_test:
self.get_scrap_items()
self.set_missing_values()