Skip to content

Commit 0431b8b

Browse files
committed
Merge pull request #784 from pytest-dev/create-dirs-xml-log
Automatically create directories for junit-xml and resultlog
2 parents 0c05b90 + 2653024 commit 0431b8b

File tree

8 files changed

+74
-2
lines changed

8 files changed

+74
-2
lines changed

.travis.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1+
sudo: false
12
language: python
23
# command to install dependencies
3-
install: "pip install -U detox"
4+
install: "pip install -U tox"
45
# # command to run tests
5-
script: detox --recreate -i ALL=https://devpi.net/hpk/dev/
6+
env:
7+
matrix:
8+
- TESTENV=flakes
9+
- TESTENV=py26
10+
- TESTENV=py27
11+
- TESTENV=py34
12+
- TESTENV=pypy
13+
- TESTENV=py27-pexpect
14+
- TESTENV=py33-pexpect
15+
- TESTENV=py27-nobyte
16+
- TESTENV=py33
17+
- TESTENV=py27-xdist
18+
- TESTENV=py33-xdist
19+
- TESTENV=py27
20+
- TESTENV=py27-trial
21+
- TESTENV=py33
22+
- TESTENV=py33-trial
23+
# inprocess tests by default were introduced in 2.8 only;
24+
# this TESTENV should be enabled when merged back to master
25+
#- TESTENV=py27-subprocess
26+
- TESTENV=doctesting
27+
- TESTENV=py27-cxfreeze
28+
- TESTENV=coveralls
29+
script: tox --recreate -i ALL=https://devpi.net/hpk/dev/ -e $TESTENV
630

731
notifications:
832
irc:

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Andreas Zeidler
88
Andy Freeland
99
Anthon van der Neut
1010
Armin Rigo
11+
Aron Curzon
1112
Benjamin Peterson
1213
Bob Ippolito
1314
Brian Dorsey

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
2.7.2 (compared to 2.7.1)
22
-----------------------------
33

4+
- Automatically create directory for junitxml and results log.
5+
Thanks Aron Curzon.
6+
47
- fix issue713: JUnit XML reports for doctest failures.
58
Thanks Punyashloka Biswal.
69

_pytest/junitxml.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ def pytest_sessionstart(self):
205205
self.suite_start_time = time.time()
206206

207207
def pytest_sessionfinish(self):
208+
dirname = os.path.dirname(os.path.abspath(self.logfile))
209+
if not os.path.isdir(dirname):
210+
os.makedirs(dirname)
208211
logfile = open(self.logfile, 'w', encoding='utf-8')
209212
suite_stop_time = time.time()
210213
suite_time_delta = suite_stop_time - self.suite_start_time

_pytest/resultlog.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import py
6+
import os
67

78
def pytest_addoption(parser):
89
group = parser.getgroup("terminal reporting", "resultlog plugin options")
@@ -14,6 +15,9 @@ def pytest_configure(config):
1415
resultlog = config.option.resultlog
1516
# prevent opening resultlog on slave nodes (xdist)
1617
if resultlog and not hasattr(config, 'slaveinput'):
18+
dirname = os.path.dirname(os.path.abspath(resultlog))
19+
if not os.path.isdir(dirname):
20+
os.makedirs(dirname)
1721
logfile = open(resultlog, 'w', 1) # line buffered
1822
config._resultlog = ResultLog(config, logfile)
1923
config.pluginmanager.register(config._resultlog)

testing/test_junitxml.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ def test_func():
474474
assert result.ret == 0
475475
assert testdir.tmpdir.join("a/x.xml").check()
476476

477+
def test_logxml_makedir(testdir):
478+
"""--junitxml should automatically create directories for the xml file"""
479+
testdir.makepyfile("""
480+
def test_pass():
481+
pass
482+
""")
483+
result = testdir.runpytest("--junitxml=path/to/results.xml")
484+
assert result.ret == 0
485+
assert testdir.tmpdir.join("path/to/results.xml").check()
486+
477487
def test_escaped_parametrized_names_xml(testdir):
478488
testdir.makepyfile("""
479489
import pytest

testing/test_resultlog.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ def test_xfail_norun():
180180
"x *:test_xfail_norun",
181181
])
182182

183+
def test_makedir_for_resultlog(testdir, LineMatcher):
184+
"""--resultlog should automatically create directories for the log file"""
185+
testdir.plugins.append("resultlog")
186+
testdir.makepyfile("""
187+
import pytest
188+
def test_pass():
189+
pass
190+
""")
191+
testdir.runpytest("--resultlog=path/to/result.log")
192+
lines = testdir.tmpdir.join("path/to/result.log").readlines(cr=0)
193+
LineMatcher(lines).fnmatch_lines([
194+
". *:test_pass",
195+
])
196+
197+
183198
def test_no_resultlog_on_slaves(testdir):
184199
config = testdir.parseconfig("-p", "resultlog", "--resultlog=resultlog")
185200

tox.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ commands=
132132
{envpython} runtests_setup.py build --build-exe build
133133
{envpython} tox_run.py
134134

135+
[testenv:coveralls]
136+
changedir=testing
137+
basepython=python3.4
138+
deps =
139+
{[testenv]deps}
140+
coveralls
141+
commands=
142+
coverage run --source=_pytest {envdir}/bin/py.test
143+
coverage report -m
144+
coveralls
145+
passenv=COVERALLS_REPO_TOKEN
146+
135147
[pytest]
136148
minversion=2.0
137149
plugins=pytester

0 commit comments

Comments
 (0)