Some modules have caches. There is a need to clear all tests before running tests. Brett proposed to add in all modules with caches a function with the standardized name which is responsible for clearing module related caches. [1]
The proposed PR adds a new function clear_caches() in the sys module. It iterates all imported modules and calls function __clearcache__() if it is defined.
def clear_caches():
for mod in reversed(list(sys.modules.values())):
if hasattr(mod, '__clearcache__'):
mod.__clearcache__()
clear_caches() will be used in test.regrtest and can be used in user code. The PR defines also function __clearcache__ for modules which are cleared manually in the current code.
This is a preliminary implementation, bikeshedding is welcome.
[1] https://mail.python.org/pipermail/python-ideas/2019-March/056165.html |