From 433115f62d6c7a62b57ae74faebf9d3c92c4ec52 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 16 Jan 2023 18:43:52 +0530 Subject: [PATCH] test: rollback test transaction after executing cmd (#19606) In command tests if connection is active then due to repeatable read isolation you will continue to read old data which might be modified by the command you're trying to test. It makes sense to end transaction after each command execution here. [skip ci] --- frappe/tests/test_commands.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frappe/tests/test_commands.py b/frappe/tests/test_commands.py index 83901fd9c4c0..f8f39214400e 100644 --- a/frappe/tests/test_commands.py +++ b/frappe/tests/test_commands.py @@ -143,6 +143,9 @@ def setUpClass(cls) -> None: @classmethod def execute(self, command, kwargs=None): + # tests might have written to DB which wont be visible to commands until we end current transaction + frappe.db.commit() + site = {"site": frappe.local.site} cmd_input = None if kwargs: @@ -165,6 +168,9 @@ def execute(self, command, kwargs=None): self.stderr = clean(self._proc.stderr) self.returncode = clean(self._proc.returncode) + # Commands might have written to DB which wont be visible until we end current transaction + frappe.db.rollback() + @classmethod def setup_test_site(cls): cmd_config = { @@ -407,24 +413,17 @@ def test_set_password(self): self.execute("bench --site {site} set-password Administrator test1") self.assertEqual(self.returncode, 0) - frappe.db.rollback() self.assertEqual(check_password("Administrator", "test1"), "Administrator") - # to release the lock taken by check_password - frappe.db.rollback() self.execute("bench --site {site} set-admin-password test2") self.assertEqual(self.returncode, 0) - frappe.db.rollback() self.assertEqual(check_password("Administrator", "test2"), "Administrator") - frappe.db.rollback() # Reset it back to original password original_password = frappe.conf.admin_password or "admin" self.execute("bench --site {site} set-admin-password %s" % original_password) self.assertEqual(self.returncode, 0) - frappe.db.rollback() self.assertEqual(check_password("Administrator", original_password), "Administrator") - frappe.db.rollback() @skipIf( not (