On Thu, Feb 14, 2019 at 3:25 PM Eric Snow <ericsnowcurrently at gmail.com> wrote: > On Thu, Feb 14, 2019, 02:47 Ronald Oussoren via Python-Dev < > python-dev at python.org wrote: > >> >> I usually use shutil.rmtree for tests that need to create temporary >> files, and create a temporary directory for those files (that is, use >> tempfile.mkdtemp in setUp() and use shutil.rmtree in tearDown()). That way >> I don’t have to adjust house-keeping code when I make changes to test code. >> > > Same here. > > -eric > >> What I generally do is avoid relying on tempfile.mkdtemp() and always use TESTFN instead. I think it's cleaner as a pradigm because it's an incentive to not pollute the single unit tests with `self.addCleanup()` instructions (the whole cleanup logic is always supposed to occur in setUp/tearDown): TESTFN = support.TESTFN TESTFN2 = TESTFN + '2' class FilesystemTest(unittest.TestCase): def setUp(self): remove_file_or_dir(TESTFN) remove_file_or_dir(TESTFN2) tearDown = setUp def test_mkdir(self): ... def test_listdir(self): ... def test_rename(self): ... -- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20190214/854e57a6/attachment.html>
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