From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id EE62913888F for ; Fri, 30 Oct 2015 22:41:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DB56E21C034; Fri, 30 Oct 2015 22:40:55 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6D81621C033 for ; Fri, 30 Oct 2015 22:40:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 89C38340AC0 for ; Fri, 30 Oct 2015 22:40:44 +0000 (UTC) From: Mike Frysinger To: gentoo-portage-dev@lists.gentoo.org Subject: [gentoo-portage-dev] [PATCH v2] runtests: create a global tempdir to hold subtest files Date: Fri, 30 Oct 2015 18:40:43 -0400 Message-Id: <1446244843-7518-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 2.5.2 In-Reply-To: <1446228019-5147-1-git-send-email-vapier@gentoo.org> References: <1446228019-5147-1-git-send-email-vapier@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 79860d2f-6b12-4ab5-944d-20d317df05f3 X-Archives-Hash: d8aa956dca1c7fe4c538675ec3d96172 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. --- v2 - make tempdir setup more robust per Zac runtests | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/runtests b/runtests index 36243c6..89c6e14 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,34 @@ 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() + tempdir = None + 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 tempdir is not None: + 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