Skip to content

Commit

Permalink
Run all tests in the dedicated temp dir, which is auto-deleted at the…
Browse files Browse the repository at this point in the history
… end. The individual test processes create their own temps as subdirectories under this temp dir. (#232)

Co-authored-by: Lukáš Cerman <lukas.cerman@eccam.com>
  • Loading branch information
lcerman and lcerman-eccam authored Oct 11, 2020
1 parent 9cee836 commit cb52c52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 17 additions & 1 deletion green/cmdline.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import unicode_literals
import os
import sys
import tempfile

# Importing from green (other than config) is done after coverage initialization
import green.config as config


def main(argv=None, testing=False):
def _main(argv, testing):
args = config.parseArguments(argv)
args = config.mergeConfig(args, testing)

Expand Down Expand Up @@ -77,5 +78,20 @@ def main(argv=None, testing=False):
return int(not result.wasSuccessful())


def main(argv=None, testing=False):
# create the temp dir only once (i.e., not while in the recursed call)
if os.environ.get('TMPDIR') is None:
with tempfile.TemporaryDirectory() as temp_dir_for_tests:
try:
os.environ['TMPDIR'] = temp_dir_for_tests
tempfile.tempdir = temp_dir_for_tests
return _main(argv, testing)
finally:
del os.environ['TMPDIR']
tempfile.tempdir = None
else:
return _main(argv, testing)


if __name__ == "__main__": # pragma: no cover
sys.exit(main())
6 changes: 0 additions & 6 deletions green/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,6 @@ def raise_internal_failure(msg):

def cleanup():
# Restore the state of the temp directory
# TODO: Make this not necessary on macOS+Python3 (see #173)
if sys.version_info[0] == 2:
try:
shutil.rmtree(tempfile.tempdir, ignore_errors=True)
except:
pass
tempfile.tempdir = saved_tempdir
queue.put(None)
# Finish coverage
Expand Down

0 comments on commit cb52c52

Please sign in to comment.