Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run all tests in the dedicated temp dir #232

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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