aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting/core
diff options
context:
space:
mode:
Diffstat (limited to 'xtesting/core')
-rw-r--r--xtesting/core/feature.py29
-rw-r--r--xtesting/core/unit.py19
2 files changed, 25 insertions, 23 deletions
diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py
index feae9885..b41519d0 100644
--- a/xtesting/core/feature.py
+++ b/xtesting/core/feature.py
@@ -107,20 +107,21 @@ class BashFeature(Feature):
os.makedirs(self.res_dir)
with open(self.result_file, 'w') as f_stdout:
self.__logger.info("Calling %s", cmd)
- process = subprocess.Popen(
- cmd, shell=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- for line in iter(process.stdout.readline, b''):
- if console:
- sys.stdout.write(line.decode("utf-8"))
- f_stdout.write(line.decode("utf-8"))
- try:
- process.wait(timeout=max_duration)
- except subprocess.TimeoutExpired:
- process.kill()
- self.__logger.info(
- "Killing process after %d second(s).", max_duration)
- return -2
+ with subprocess.Popen(
+ cmd, shell=True, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT) as process:
+ for line in iter(process.stdout.readline, b''):
+ if console:
+ sys.stdout.write(line.decode("utf-8"))
+ f_stdout.write(line.decode("utf-8"))
+ try:
+ process.wait(timeout=max_duration)
+ except subprocess.TimeoutExpired:
+ process.kill()
+ self.__logger.info(
+ "Killing process after %d second(s).",
+ max_duration)
+ return -2
with open(self.result_file, 'r') as f_stdin:
self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip())
return process.returncode
diff --git a/xtesting/core/unit.py b/xtesting/core/unit.py
index 8bcf163a..e6c3cd87 100644
--- a/xtesting/core/unit.py
+++ b/xtesting/core/unit.py
@@ -43,10 +43,11 @@ class Suite(testcase.TestCase):
Exception
"""
stream.seek(0)
- stats = subprocess.Popen(
- ['subunit-stats'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- output, _ = stats.communicate(stream.read())
- cls.__logger.info("\n\n%s", output.decode("utf-8"))
+ with subprocess.Popen(
+ ['subunit-stats'], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE) as stats:
+ output, _ = stats.communicate(stream.read())
+ cls.__logger.info("\n\n%s", output.decode("utf-8"))
def generate_xunit(self, stream):
"""Generate junit report from subunit stream
@@ -56,11 +57,11 @@ class Suite(testcase.TestCase):
"""
stream.seek(0)
with open("{}/results.xml".format(self.res_dir), "w") as xml:
- stats = subprocess.Popen(
- ['subunit2junitxml'], stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
- output, _ = stats.communicate(stream.read())
- xml.write(output.decode("utf-8"))
+ with subprocess.Popen(
+ ['subunit2junitxml'], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE) as stats:
+ output, _ = stats.communicate(stream.read())
+ xml.write(output.decode("utf-8"))
def generate_html(self, stream):
"""Generate html report from subunit stream