From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: [gentoo-portage-dev] [PATCH] runtests: create a global tempdir to hold subtest files
Date: Fri, 30 Oct 2015 14:00:19 -0400 [thread overview]
Message-ID: <1446228019-5147-1-git-send-email-vapier@gentoo.org> (raw)
A lot of unittests currently leak content in /tmp when they run.
Rather than explicitly track down every failing test (which we can
do regardless of this), have the runtest runner create a global
tempdir and use that as a base for children tests. Then when the
runtest script finishes, it takes care of nuking everything.
---
runtests | 46 +++++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/runtests b/runtests
index 36243c6..fc6de0a 100755
--- a/runtests
+++ b/runtests
@@ -15,8 +15,10 @@ from __future__ import print_function
import argparse
import os
-import sys
+import shutil
import subprocess
+import sys
+import tempfile
# These are the versions we fully support and require to pass tests.
@@ -91,6 +93,8 @@ $ %(prog)s pym/portage/tests/xpak/test_decodeint.py
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=epilog)
+ parser.add_argument('--keep-temp', default=False, action='store_true',
+ help='Do not delete the temporary directory when exiting')
parser.add_argument('--color', type=str, default=None,
help='Whether to use colorized output (default is auto)')
parser.add_argument('--python-versions', action='append',
@@ -116,20 +120,32 @@ def main(argv):
else:
pyversions.extend(ver.split())
- # Actually test those versions now.
- statuses = []
- for ver in pyversions:
- prog = get_python_executable(ver)
- cmd = [prog, '-b', '-Wd', 'pym/portage/tests/runTests.py'] + args
- if os.access(prog, os.X_OK):
- print('%sTesting with Python %s...%s' %
- (colors.GOOD, ver, colors.NORMAL))
- statuses.append(subprocess.call(cmd))
- elif not ignore_missing:
- print('%sCould not find requested Python %s%s' %
- (colors.BAD, ver, colors.NORMAL))
- statuses.append(1)
- print()
+ try:
+ # Set up a single tempdir for all the tests to use.
+ # This way we know the tests won't leak things on us.
+ tempdir = tempfile.mkdtemp(prefix='portage.runtests.')
+ os.environ['TMPDIR'] = tempdir
+
+ # Actually test those versions now.
+ statuses = []
+ for ver in pyversions:
+ prog = get_python_executable(ver)
+ cmd = [prog, '-b', '-Wd', 'pym/portage/tests/runTests.py'] + args
+ if os.access(prog, os.X_OK):
+ print('%sTesting with Python %s...%s' %
+ (colors.GOOD, ver, colors.NORMAL))
+ statuses.append(subprocess.call(cmd))
+ elif not ignore_missing:
+ print('%sCould not find requested Python %s%s' %
+ (colors.BAD, ver, colors.NORMAL))
+ statuses.append(1)
+ print()
+ finally:
+ if opts.keep_temp:
+ print('Temporary directory left behind:\n%s' % tempdir)
+ else:
+ # Nuke our tempdir and anything that might be under it.
+ shutil.rmtree(tempdir, True)
# Then summarize it all.
print('\nSummary:\n')
--
2.5.2
next reply other threads:[~2015-10-30 18:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-30 18:00 Mike Frysinger [this message]
2015-10-30 18:52 ` [gentoo-portage-dev] [PATCH] runtests: create a global tempdir to hold subtest files Zac Medico
2015-10-30 18:55 ` Zac Medico
2015-10-30 22:40 ` [gentoo-portage-dev] [PATCH v2] " Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1446228019-5147-1-git-send-email-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox