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 (