Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] runtests: create a global tempdir to hold subtest files
Date: Fri, 30 Oct 2015 18:52:49
Message-Id: 5633BC75.2010305@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] runtests: create a global tempdir to hold subtest files by Mike Frysinger
1 On 10/30/2015 11:00 AM, Mike Frysinger wrote:
2
3 > + try:
4 > + # Set up a single tempdir for all the tests to use.
5 > + # This way we know the tests won't leak things on us.
6 > + tempdir = tempfile.mkdtemp(prefix='portage.runtests.')
7 [snip]
8 > + finally:
9 > + if opts.keep_temp:
10 > + print('Temporary directory left behind:\n%s' % tempdir)
11 > + else:
12 > + # Nuke our tempdir and anything that might be under it.
13 > + shutil.rmtree(tempdir, True)
14 >
15 > # Then summarize it all.
16 > print('\nSummary:\n')
17 >
18
19 This will raise NameError if mkdtemp for some reason. For absolute
20 correctness, you need to call mkdtemp before try, or set tempdir = None
21 before the try and check that it's not None before calling rmtree.
22 --
23 Thanks,
24 Zac

Replies