On Thu, Feb 21, 2008 at 7:43 AM, Giampaolo Rodola' <gnewsg at gmail.com> wrote: > > I have usually seen a lot of tests implemented like this: > > from test.test_support import TESTFN, unlink > import unittest > > class TestCase(unittest.TestCase): > > def setUp(self): > self.file = None > > def tearDown(self): > if self.file is not None: > self.file.close() > unlink(TESTFN) > > def test_something(self): > self.file = open(TESTFN, 'r') > ... Yes, but this is not as robust as it could be. It's better to also unlink/rmtree in the setUp. That way if the file doesn't get cleaned up (interpreter crash, KeyboardInterrupt, file not closed on Windows, exception in tearDown, etc), the test won't fail on the next run or the next test that assumes TESTFN doesn't exist won't fail. n
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4