On Thu, Feb 21, 2008 at 7:43 AM, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > On 21 Feb, 12:30, "Virgil Dupras" <[EMAIL PROTECTED]> wrote: > > Hi devs, > > > > > > Specifically, I'd like to know about files managements in tests. Is > > every test expected to clean after itself, or is there an automatic > > cleanup mechanism in place? > > 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') > ... > > > > > Even more specifically, I'd like to create > > a test for the proposed patch inhttp://bugs.python.org/issue2127so I > > > need to create a subdir with non-ascii character in it, then connect > > to a db in it. So, do I need to do the cleanup in the test? Is there a > > special path I can write to that will automatically be cleaned up? > > I don't think so. > You could create a directory in setUp method by using tempfile.mkdtemp > and then remove it in tearDown.
Specifically, clean it up with shutil.rmtree() > > I guess I could find the answer in regrtest.py, but frankly, this unit > > is a little bit overwhelming. > > > > If there is no guide, am I the only one to think it would be a good > > idea to have one (Yeah, I could volunteer to write it)? > > Don't know whether Lib/test/readme.txt could be considered a guide but > it contains a lot of useful information for developers. > > > Hope this helps a little > > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/guido%40python.org > -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com