diff --git a/AUTHORS b/AUTHORS index a24447c33..1311cc83c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,6 +8,7 @@ Andreas Zeidler Andy Freeland Anthon van der Neut Armin Rigo +Aron Curzon Benjamin Peterson Bob Ippolito Brian Dorsey @@ -33,6 +34,7 @@ Harald Armin Massa Ian Bicking Jaap Broekhuizen Jan Balster +Janne Vanhala Jason R. Coombs Jurko Gospodnetić Katarzyna Jachim @@ -51,4 +53,3 @@ Samuele Pedroni Tom Viner Trevor Bekolay Wouter van Ackooy -Janne Vanhala diff --git a/CHANGELOG b/CHANGELOG index b0281d291..fea0e9989 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -65,6 +65,17 @@ - fix issue741: make running output from testdir.run copy/pasteable Thanks Bruno Oliveira. +2.7.2 (compared to 2.7.1) +----------------------------- + +- Automatically create directory for junitxml and results log. + Thanks Aron Curzon. + +- fix issue713: JUnit XML reports for doctest failures. + Thanks Punyashloka Biswal. + +- fix issue735: assertion failures on debug versions of Python 3.4+ + Thanks Benjamin Peterson. 2.7.1 (compared to 2.7.0) ----------------------------- diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index bcdf85781..2a1220625 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -205,6 +205,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.isdir(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..3670f0214 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.isdir(dirname): + os.makedirs(dirname) logfile = open(resultlog, 'w', 1) # line buffered config._resultlog = ResultLog(config, logfile) config.pluginmanager.register(config._resultlog) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 4c54a14b6..d8b18b177 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -478,6 +478,16 @@ def test_logxml_changingdir(testdir): assert result.ret == 0 assert testdir.tmpdir.join("a/x.xml").check() +def test_logxml_makedir(testdir): + """--junitxml should automatically create directories for the xml file""" + 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..ef1d6d040 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -180,6 +180,21 @@ def test_generic(testdir, LineMatcher): "x *:test_xfail_norun", ]) +def test_makedir_for_resultlog(testdir, LineMatcher): + """--resultlog should automatically create directories for the log file""" + 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")