From 1db5c95414480cdb21804d7d8ef898a5f69b7c34 Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 14:36:18 -0700 Subject: [PATCH 1/3] 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) From 9346e18d8c2e611747fe2b7c82ab6f0ae38aec55 Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 15:36:04 -0700 Subject: [PATCH 2/3] Test creating directory for junit-xml and resultlog --- testing/test_junitxml.py | 9 +++++++++ testing/test_resultlog.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 9da836bbe..65e3ca03f 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -474,6 +474,15 @@ def test_logxml_changingdir(testdir): assert result.ret == 0 assert testdir.tmpdir.join("a/x.xml").check() +def test_logxml_makedir(testdir): + testdir.makepyfile(""" + def test_pass(): + pass + """) + result = testdir.runpytest("--junitxml=path/to/results.xml") + assert result.ret == 0 + assert testdir.tmpdir.join("path/to/results.xml").check() + def test_escaped_parametrized_names_xml(testdir): testdir.makepyfile(""" import pytest diff --git a/testing/test_resultlog.py b/testing/test_resultlog.py index e4f3faccc..96686d3a2 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -180,6 +180,20 @@ def test_generic(testdir, LineMatcher): "x *:test_xfail_norun", ]) +def test_makedir_for_resultlog(testdir, LineMatcher): + testdir.plugins.append("resultlog") + testdir.makepyfile(""" + import pytest + def test_pass(): + pass + """) + testdir.runpytest("--resultlog=path/to/result.log") + lines = testdir.tmpdir.join("path/to/result.log").readlines(cr=0) + LineMatcher(lines).fnmatch_lines([ + ". *:test_pass", + ]) + + def test_no_resultlog_on_slaves(testdir): config = testdir.parseconfig("-p", "resultlog", "--resultlog=resultlog") From 1871d526ace55bad1cffc0ca9d8b652a6a6c10ab Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 15:37:17 -0700 Subject: [PATCH 3/3] Update CHANGELOG and AUTHORS --- AUTHORS | 1 + CHANGELOG | 3 +++ 2 files changed, 4 insertions(+) diff --git a/AUTHORS b/AUTHORS index abe29c261..0b59555f0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -48,3 +48,4 @@ Nicolas Delaby Tom Viner Dave Hunt Charles Cloud +Aron Curzon diff --git a/CHANGELOG b/CHANGELOG index 334bf8b6f..c12bcce7c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 2.7.2 (compared to 2.7.1) ----------------------------- +- Automatically create directory for junitxml and results log. + Thanks Aron Curzon. + - fix issue735: assertion failures on debug versions of Python 3.4+ Thanks Benjamin Peterson.