summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMickaël Schoentgen <contact@tiger-222.fr>2019-03-08 18:38:30 +0100
committerBernát Gábor <gaborjbernat@gmail.com>2019-03-08 17:38:30 +0000
commite189e5a5821d7e3ec2066d4621fa2b411a97c1d8 (patch)
tree8c9bf793cbece83c213c7f3434712489c441d941 /src
parentb9c1647b715a326301d67fc54d5106a0a40bff15 (diff)
downloadtox-git-e189e5a5821d7e3ec2066d4621fa2b411a97c1d8.tar.gz
Fix ResourceWarning: unclosed file in Action (#1179)
Thanks!
Diffstat (limited to 'src')
-rw-r--r--src/tox/action.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/tox/action.py b/src/tox/action.py
index ba491382..20efd8e5 100644
--- a/src/tox/action.py
+++ b/src/tox/action.py
@@ -149,26 +149,25 @@ class Action(object):
def _get_standard_streams(self, capture_err, cmd_args_shell, redirect, returnout):
stdout = out_path = fin = None
stderr = subprocess.STDOUT if capture_err else None
- stdout_file = None
+
if self.generate_tox_log or redirect:
out_path = self.get_log_path(self.name)
- stdout_file = out_path.open("wt")
- stdout_file.write(
- "actionid: {}\nmsg: {}\ncmdargs: {!r}\n\n".format(
- self.name, self.msg, cmd_args_shell
+ with out_path.open("wt") as stdout, out_path.open("rb") as fin:
+ stdout.write(
+ "actionid: {}\nmsg: {}\ncmdargs: {!r}\n\n".format(
+ self.name, self.msg, cmd_args_shell
+ )
)
- )
- stdout_file.flush()
- fin = out_path.open("rb")
- fin.read() # read the header, so it won't be written to stdout
- stdout = stdout_file
- elif returnout:
+ stdout.flush()
+ fin.read() # read the header, so it won't be written to stdout
+
+ yield fin, out_path, stderr, stdout
+ return
+
+ if returnout:
stdout = subprocess.PIPE
- try:
- yield fin, out_path, stderr, stdout
- finally:
- if stdout_file is not None:
- stdout_file.close()
+
+ yield fin, out_path, stderr, stdout
def get_log_path(self, actionid):
return get_unique_file(