[Tutor] Writing unit tests that involve email

Arnel Legaspi jalespring at gmail.com
Wed Jul 17 09:09:20 CEST 2013


Peter Otten wrote:
 > Arnel Legaspi wrote:
 > > class TestReadingSendingPostFile(unittest.TestCase):
 > >       def test_wrongconfigfile(self):
 > >           clear_args()
 > >           add_testfiles('post.md', 'bloginfo.ini')
 > >           self.assertRaises(IOError)
 >
 > Where did you catch up that idiom? The assertRaises() call above does
 > nothing. You must either invoke it with a callable
 >
 > or use it as a context manager
 >
 > with self.assertRaises(IOError):
 >     ... # code supposed to raise an IOError

Ah, so that's how it was supposed to be used. That idiom was a product 
of my misunderstanding how assertRaises() was described in the manual.

Thanks, Peter. (This really should have been the answer when I asked 
about it on StackOverflow.)

--Arnel


More information about the Tutor mailing list