Make assert_warns API more sensible and add tests