Using ``with warnings.catch_warnings:`` would be cleaner.