From ded8cdfcb7ba0286f8993cb1a421a727eb08e401 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 3 Jan 2025 11:44:12 +0530 Subject: [PATCH] test: undo breaking change to test-fixture regeneration (#29034) I don't like test fixtures at all but breaking this is so pointless. I can't even re-run ERPNext tests! People should overtime stop relying on hardcoded fixtures and write utils to generate them at runtime in tests. I've migrated tons of tests this way during my time in ERPNext team and those tests are far more reliable than hardcoded ones. --- frappe/deprecation_dumpster.py | 44 ++++++++++++++-------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/frappe/deprecation_dumpster.py b/frappe/deprecation_dumpster.py index f7df0bac6a..27af062aa1 100644 --- a/frappe/deprecation_dumpster.py +++ b/frappe/deprecation_dumpster.py @@ -994,36 +994,28 @@ def frappe_get_test_records(doctype): def compat_preload_test_records_upfront(candidates: list): - import os + import json + import re - if os.environ.get("OLD_FRAPPE_TEST_CLASS_RECORDS_PRELOAD"): - deprecation_warning( - "2024-11-06", - "v17", - "Please fully declare test record dependencies for each test individually; you can assert compliance of your test suite with the following GH action: https://github.com/frappe/frappe/blob/develop/.github/workflows/run-indinvidual-tests.yml", - ) - import json - import re + from frappe.tests.utils import make_test_records - from frappe.tests.utils import make_test_records + for module, path, filename in candidates: + if hasattr(module, "test_dependencies"): + for doctype in module.test_dependencies: + make_test_records(doctype, commit=True) + if hasattr(module, "EXTRA_TEST_RECORD_DEPENDENCIES"): + for doctype in module.EXTRA_TEST_RECORD_DEPENDENCIES: + make_test_records(doctype, commit=True) - for module, path, filename in candidates: - if hasattr(module, "test_dependencies"): - for doctype in module.test_dependencies: + if os.path.basename(os.path.dirname(path)) == "doctype": + # test_data_migration_connector.py > data_migration_connector.json + test_record_filename = re.sub("^test_", "", filename).replace(".py", ".json") + test_record_file_path = os.path.join(path, test_record_filename) + if os.path.exists(test_record_file_path): + with open(test_record_file_path) as f: + doc = json.loads(f.read()) + doctype = doc["name"] make_test_records(doctype, commit=True) - if hasattr(module, "EXTRA_TEST_RECORD_DEPENDENCIES"): - for doctype in module.EXTRA_TEST_RECORD_DEPENDENCIES: - make_test_records(doctype, commit=True) - - if os.path.basename(os.path.dirname(path)) == "doctype": - # test_data_migration_connector.py > data_migration_connector.json - test_record_filename = re.sub("^test_", "", filename).replace(".py", ".json") - test_record_file_path = os.path.join(path, test_record_filename) - if os.path.exists(test_record_file_path): - with open(test_record_file_path) as f: - doc = json.loads(f.read()) - doctype = doc["name"] - make_test_records(doctype, commit=True) @deprecated(