Merge pull request #28448 from blaggacao/fix/test-environment-user-idempotency

fix(testing)!: ensure idempotency on the test environment user
This commit is contained in:
Akhil Narang 2024-11-14 15:36:58 +05:30 committed by GitHub
commit 3dff39946d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View file

@ -19,6 +19,7 @@ module.exports = {
"revert",
"style",
"test",
"deprecate", // deprecation decision
],
],
},

View file

@ -85,6 +85,13 @@ class ParallelTestRunner:
print("running tests from", "/".join(file_info))
return
from frappe.deprecation_dumpster import deprecation_warning
deprecation_warning(
"2024-11-13",
"v17",
"Setting the test environment user to 'Administrator' by the test runner is deprecated. The UnitTestCase now ensures a consistent user environment on set up and tear down at the class level. ",
)
frappe.set_user("Administrator")
path, filename = file_info
module = self.get_module(path, filename)

View file

@ -49,6 +49,10 @@ class UnitTestCase(unittest.TestCase, BaseTestCase):
super().setUpClass()
cls.doctype = _get_doctype_from_module(cls)
cls.module = frappe.get_module(cls.__module__)
# Test Environment
frappe.set_user("Administrator")
# Test Environment (cleanup)
cls.addClassCleanup(frappe.set_user, "Administrator")
cls._unit_test_case_class_setup_done = True
def assertQueryEqual(self, first: str, second: str) -> None: