Not sure that I agree there is a testing need to clear all caches regardless of what they do. Test code should explicitly state whether it relies on a particular cache being cleared at some particular point in time.
Also, the concept of "need to clear all caches" isn't well-formed. Would you want sys.intern caches to be cleared? What about the internal caches in SQLite?
And do you think polling for a new magic attribute is the right approach? We would get looser coupling and better control by letting modules register themselves as needed.
--- re.py ---
sys.register_cache_clear_function(callback=purge, doc='pattern cache and re cache')
--- ipaddress.py --
sys.register(IPv4Address.is_private.is_getter.cache_clear, doc='check for private networks) |