test: avoid flaky behaviour on test ordering
If a test clears local.response and another test depends on it being fresh inited then tests can fail. E.g. response.docs might not exist.
This commit is contained in:
parent
13304cd36d
commit
47af97661a
3 changed files with 14 additions and 16 deletions
|
|
@ -24,7 +24,7 @@ if click_ctx:
|
|||
TEST_WEIGHT_OVERRIDES = {
|
||||
# XXX: command tests are significantly overweight, need a better heuristic than test count
|
||||
# Possible better solution: stats from previous test runs.
|
||||
"test_commands.py": 20,
|
||||
"test_commands.py": 10,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class IntegrationTestCase(UnitTestCase):
|
|||
frappe.db.before_commit.add(_commit_watcher)
|
||||
|
||||
# enqueue teardown actions (executed in LIFO order)
|
||||
cls.addClassCleanup(_restore_thread_locals, copy.deepcopy(frappe.local.flags))
|
||||
cls.addClassCleanup(_restore_ctx_locals, copy.deepcopy(frappe.local.flags))
|
||||
cls.addClassCleanup(_rollback_db)
|
||||
cls._integration_test_case_class_setup_done = True
|
||||
|
||||
|
|
@ -183,12 +183,13 @@ def _rollback_db():
|
|||
frappe.db.rollback()
|
||||
|
||||
|
||||
def _restore_thread_locals(flags):
|
||||
def _restore_ctx_locals(flags):
|
||||
frappe.local.flags = flags
|
||||
frappe.local.error_log = []
|
||||
frappe.local.message_log = []
|
||||
frappe.local.debug_log = []
|
||||
frappe.local.conf = frappe._dict(frappe.get_site_config())
|
||||
frappe.local.response = frappe._dict({"docs": []})
|
||||
frappe.local.cache = {}
|
||||
frappe.local.lang = "en"
|
||||
frappe.local.preload_assets = {"style": [], "script": [], "icons": []}
|
||||
|
|
|
|||
|
|
@ -74,19 +74,16 @@ class TestClient(IntegrationTestCase):
|
|||
def test_run_doc_method(self):
|
||||
from frappe.handler import execute_cmd
|
||||
|
||||
if not frappe.db.exists("Report", "Test Run Doc Method"):
|
||||
report = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Report",
|
||||
"ref_doctype": "User",
|
||||
"report_name": "Test Run Doc Method",
|
||||
"report_type": "Query Report",
|
||||
"is_standard": "No",
|
||||
"roles": [{"role": "System Manager"}],
|
||||
}
|
||||
).insert()
|
||||
else:
|
||||
report = frappe.get_doc("Report", "Test Run Doc Method")
|
||||
report = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Report",
|
||||
"ref_doctype": "User",
|
||||
"report_name": frappe.generate_hash(),
|
||||
"report_type": "Query Report",
|
||||
"is_standard": "No",
|
||||
"roles": [{"role": "System Manager"}],
|
||||
}
|
||||
).insert()
|
||||
|
||||
frappe.local.request = frappe._dict()
|
||||
frappe.local.request.method = "GET"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue