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 |
v2 |
8 |
- make tempdir setup more robust per Zac |
9 |
|
10 |
runtests | 48 +++++++++++++++++++++++++++++++++--------------- |
11 |
1 file changed, 33 insertions(+), 15 deletions(-) |
12 |
|
13 |
diff --git a/runtests b/runtests |
14 |
index 36243c6..89c6e14 100755 |
15 |
--- a/runtests |
16 |
+++ b/runtests |
17 |
@@ -15,8 +15,10 @@ from __future__ import print_function |
18 |
|
19 |
import argparse |
20 |
import os |
21 |
-import sys |
22 |
+import shutil |
23 |
import subprocess |
24 |
+import sys |
25 |
+import tempfile |
26 |
|
27 |
|
28 |
# These are the versions we fully support and require to pass tests. |
29 |
@@ -91,6 +93,8 @@ $ %(prog)s pym/portage/tests/xpak/test_decodeint.py |
30 |
description=__doc__, |
31 |
formatter_class=argparse.RawDescriptionHelpFormatter, |
32 |
epilog=epilog) |
33 |
+ parser.add_argument('--keep-temp', default=False, action='store_true', |
34 |
+ help='Do not delete the temporary directory when exiting') |
35 |
parser.add_argument('--color', type=str, default=None, |
36 |
help='Whether to use colorized output (default is auto)') |
37 |
parser.add_argument('--python-versions', action='append', |
38 |
@@ -116,20 +120,34 @@ def main(argv): |
39 |
else: |
40 |
pyversions.extend(ver.split()) |
41 |
|
42 |
- # Actually test those versions now. |
43 |
- statuses = [] |
44 |
- for ver in pyversions: |
45 |
- prog = get_python_executable(ver) |
46 |
- cmd = [prog, '-b', '-Wd', 'pym/portage/tests/runTests.py'] + args |
47 |
- if os.access(prog, os.X_OK): |
48 |
- print('%sTesting with Python %s...%s' % |
49 |
- (colors.GOOD, ver, colors.NORMAL)) |
50 |
- statuses.append(subprocess.call(cmd)) |
51 |
- elif not ignore_missing: |
52 |
- print('%sCould not find requested Python %s%s' % |
53 |
- (colors.BAD, ver, colors.NORMAL)) |
54 |
- statuses.append(1) |
55 |
- print() |
56 |
+ tempdir = None |
57 |
+ try: |
58 |
+ # Set up a single tempdir for all the tests to use. |
59 |
+ # This way we know the tests won't leak things on us. |
60 |
+ tempdir = tempfile.mkdtemp(prefix='portage.runtests.') |
61 |
+ os.environ['TMPDIR'] = tempdir |
62 |
+ |
63 |
+ # Actually test those versions now. |
64 |
+ statuses = [] |
65 |
+ for ver in pyversions: |
66 |
+ prog = get_python_executable(ver) |
67 |
+ cmd = [prog, '-b', '-Wd', 'pym/portage/tests/runTests.py'] + args |
68 |
+ if os.access(prog, os.X_OK): |
69 |
+ print('%sTesting with Python %s...%s' % |
70 |
+ (colors.GOOD, ver, colors.NORMAL)) |
71 |
+ statuses.append(subprocess.call(cmd)) |
72 |
+ elif not ignore_missing: |
73 |
+ print('%sCould not find requested Python %s%s' % |
74 |
+ (colors.BAD, ver, colors.NORMAL)) |
75 |
+ statuses.append(1) |
76 |
+ print() |
77 |
+ finally: |
78 |
+ if tempdir is not None: |
79 |
+ if opts.keep_temp: |
80 |
+ print('Temporary directory left behind:\n%s' % tempdir) |
81 |
+ else: |
82 |
+ # Nuke our tempdir and anything that might be under it. |
83 |
+ shutil.rmtree(tempdir, True) |
84 |
|
85 |
# Then summarize it all. |
86 |
print('\nSummary:\n') |
87 |
-- |
88 |
2.5.2 |