From 1db5c95414480cdb21804d7d8ef898a5f69b7c34 Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 14:36:18 -0700 Subject: [PATCH] Automatically create directory for results --- _pytest/junitxml.py | 3 +++ _pytest/resultlog.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 6d25d8407..a248a0715 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -203,6 +203,9 @@ class LogXML(object): self.suite_start_time = time.time() def pytest_sessionfinish(self): + dirname = os.path.dirname(os.path.abspath(self.logfile)) + if not os.path.exists(dirname): + os.makedirs(dirname) logfile = open(self.logfile, 'w', encoding='utf-8') suite_stop_time = time.time() suite_time_delta = suite_stop_time - self.suite_start_time diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py index 0c100552f..44312d319 100644 --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -3,6 +3,7 @@ text file. """ import py +import os def pytest_addoption(parser): group = parser.getgroup("terminal reporting", "resultlog plugin options") @@ -14,6 +15,9 @@ def pytest_configure(config): resultlog = config.option.resultlog # prevent opening resultlog on slave nodes (xdist) if resultlog and not hasattr(config, 'slaveinput'): + dirname = os.path.dirname(os.path.abspath(resultlog)) + if not os.path.exists(dirname): + os.makedirs(dirname) logfile = open(resultlog, 'w', 1) # line buffered config._resultlog = ResultLog(config, logfile) config.pluginmanager.register(config._resultlog)