import warnings

def foo():
    warnings.warn('uhoh')

def bar():
    foo()

def main():
    warnings.simplefilter('error', UserWarning)
bar()
if __name__ == '__main__':
    main()
Django Filtering MySQL Warnings