catch_warnings blocks more robust

Explicitely calling clean_warning_registry before with block.
Fix for #3494 
This change breaks PEP8 compliance