Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] runtests: create a global tempdir to hold subtest files
Date: Fri, 30 Oct 2015 18:00:38
Message-Id: 1446228019-5147-1-git-send-email-vapier@gentoo.org
1 A lot of unittests currently leak content in /tmp when they run.
2 Rather than explicitly track down every failing test (which we can
3 do regardless of this), have the runtest runner create a global
4 tempdir and use that as a base for children tests. Then when the
5 runtest script finishes, it takes care of nuking everything.
6 ---
7 runtests | 46 +++++++++++++++++++++++++++++++---------------
8 1 file changed, 31 insertions(+), 15 deletions(-)
9
10 diff --git a/runtests b/runtests
11 index 36243c6..fc6de0a 100755
12 --- a/runtests
13 +++ b/runtests
14 @@ -15,8 +15,10 @@ from __future__ import print_function
15
16 import argparse
17 import os
18 -import sys
19 +import shutil
20 import subprocess
21 +import sys
22 +import tempfile
23
24
25 # These are the versions we fully support and require to pass tests.
26 @@ -91,6 +93,8 @@ $ %(prog)s pym/portage/tests/xpak/test_decodeint.py
27 description=__doc__,
28 formatter_class=argparse.RawDescriptionHelpFormatter,
29 epilog=epilog)
30 + parser.add_argument('--keep-temp', default=False, action='store_true',
31 + help='Do not delete the temporary directory when exiting')
32 parser.add_argument('--color', type=str, default=None,
33 help='Whether to use colorized output (default is auto)')
34 parser.add_argument('--python-versions', action='append',
35 @@ -116,20 +120,32 @@ def main(argv):
36 else:
37 pyversions.extend(ver.split())
38
39 - # Actually test those versions now.
40 - statuses = []
41 - for ver in pyversions:
42 - prog = get_python_executable(ver)
43 - cmd = [prog, '-b', '-Wd', 'pym/portage/tests/runTests.py'] + args
44 - if os.access(prog, os.X_OK):
45 - print('%sTesting with Python %s...%s' %
46 - (colors.GOOD, ver, colors.NORMAL))
47 - statuses.append(subprocess.call(cmd))
48 - elif not ignore_missing:
49 - print('%sCould not find requested Python %s%s' %
50 - (colors.BAD, ver, colors.NORMAL))
51 - statuses.append(1)
52 - print()
53 + try:
54 + # Set up a single tempdir for all the tests to use.
55 + # This way we know the tests won't leak things on us.
56 + tempdir = tempfile.mkdtemp(prefix='portage.runtests.')
57 + os.environ['TMPDIR'] = tempdir
58 +
59 + # Actually test those versions now.
60 + statuses = []
61 + for ver in pyversions:
62 + prog = get_python_executable(ver)
63 + cmd = [prog, '-b', '-Wd', 'pym/portage/tests/runTests.py'] + args
64 + if os.access(prog, os.X_OK):
65 + print('%sTesting with Python %s...%s' %
66 + (colors.GOOD, ver, colors.NORMAL))
67 + statuses.append(subprocess.call(cmd))
68 + elif not ignore_missing:
69 + print('%sCould not find requested Python %s%s' %
70 + (colors.BAD, ver, colors.NORMAL))
71 + statuses.append(1)
72 + print()
73 + finally:
74 + if opts.keep_temp:
75 + print('Temporary directory left behind:\n%s' % tempdir)
76 + else:
77 + # Nuke our tempdir and anything that might be under it.
78 + shutil.rmtree(tempdir, True)
79
80 # Then summarize it all.
81 print('\nSummary:\n')
82 --
83 2.5.2

Replies