How to test with Python’s unittest that a warning has been thrown? January 31, 2023 by Tarik Starting with Python 3.2, you can simply use assertWarns() method. with self.assertWarns(Warning): do_something()