fix(UAE VAT 201): bypass helper cache in tests

frappe.local is request-scoped, not test-scoped — it survives
across unit-test methods. Two tests calling get_standard_rated_
expenses_total({"company": "_Test Company UAE VAT"}) hit the
same cache key, so the second test (foreign-currency PI, expected
917.5) was seeing 250 carried over from the first.

Short-circuit @_cached on frappe.flags.in_test so each test method
queries fresh. Production callers run one execute() per request and
have the cache cleared at the top of that call, so the optimisation
still applies there.
This commit is contained in:
Bibin
2026-06-21 17:25:19 +00:00
parent a8b6bcacc5
commit d0988dc32c

View File

@@ -48,6 +48,14 @@ def _drill_down_link(text, filters, **extra):
def _cached(fn):
def wrapper(filters, *args, **kwargs):
# ``frappe.local`` survives across unit-test methods (it is request
# scoped, not test scoped). Two tests that call the same helper with
# equivalent filter dicts would otherwise share a cached value from
# the first test's data set. Bypass the cache in tests so each
# call hits the DB; production callers (one execute() per HTTP
# request, cache cleared at its start) still see the optimisation.
if frappe.flags.in_test:
return fn(filters, *args, **kwargs)
cache = _get_cache()
key = (fn.__name__, tuple(sorted((filters or {}).items())))
if key not in cache: