assertRaises can be used as a context manager since 2.8.0 (#443). However, the behavior is different (and IMO inferior) to the unittest behavior. For example, with unittest:
with self.assertRaises(BazException) as exc:
foo('a', 'b', bar=123)
self.assertIn('baz thing', str(BazException))
This is not possible since exc is an instance of _AssertRaisesContext rather than the exception we've captured. To access the exception, I believe we need to use the .exception attribute.