def your_code():
    warnings.warn('deprecated', DeprecationWarning)

def your_test():
    with warnings.catch_warnings(record=True) as w:
        your_code()
assert len(w) > 1
Check that a function raises a warning with nose tests