def METHOD_NAME(self, fn, filename,
                   expected_exception=FileNotFoundError,
                   check_filename=True):
    with self.assertRaises(expected_exception) as c:
        fn(filename)
    exc_filename = c.exception.filename
    if check_filename:
        self.assertEqual(exc_filename, filename, "Function '%s(%a) failed "
                         "with bad filename in the exception: %a" %
                         (fn.__name__, filename, exc_filename))