import unittest class TestFull(unittest.TestCase): def check_write(self, *lines): with open('/dev/full', 'w', 1) as f: for line in lines: f.write(line) def test_write1(self): self.assertRaises(IOError, self.check_write, 'hello\n') def test_write2(self): self.assertRaises(IOError, self.check_write, 'hello', '\n') unittest.main()