Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 77
    The second snipped about what to do when argument is passed was really helpful. Commented Jun 19, 2018 at 8:07
  • 2
    I'm using 2.7.15. If afunction in self.assertRaises(ExpectedException, afunction, arg1, arg2) is the class initializer, you need to pass self as the first argument e.g., self.assertRaises(ExpectedException, Class, self, arg1, arg2) Commented Aug 24, 2018 at 15:31
  • 1
    it also work if arg must be of type parameter=value, like: self.assertRaises(ExpectedException, afunction, arg1=val1) Commented Jun 1, 2021 at 17:13
  • 2
    Note you can also just do a: with self.assertRaises(ExpectedException): and call your function normally. Commented Sep 29, 2023 at 19:43