Merge pull request #784 from pytest-dev/create-dirs-xml-log

Automatically create directories for junit-xml and resultlog
This commit is contained in:
Anatoly Bubenkov 2015-06-17 13:28:07 +02:00
commit 0431b8bb74
8 changed files with 74 additions and 2 deletions

View File

@ -1,8 +1,32 @@
sudo: false
language: python language: python
# command to install dependencies # command to install dependencies
install: "pip install -U detox" install: "pip install -U tox"
# # command to run tests # # command to run tests
script: detox --recreate -i ALL=https://devpi.net/hpk/dev/ env:
matrix:
- TESTENV=flakes
- TESTENV=py26
- TESTENV=py27
- TESTENV=py34
- TESTENV=pypy
- TESTENV=py27-pexpect
- TESTENV=py33-pexpect
- TESTENV=py27-nobyte
- TESTENV=py33
- TESTENV=py27-xdist
- TESTENV=py33-xdist
- TESTENV=py27
- TESTENV=py27-trial
- TESTENV=py33
- TESTENV=py33-trial
# inprocess tests by default were introduced in 2.8 only;
# this TESTENV should be enabled when merged back to master
#- TESTENV=py27-subprocess
- TESTENV=doctesting
- TESTENV=py27-cxfreeze
- TESTENV=coveralls
script: tox --recreate -i ALL=https://devpi.net/hpk/dev/ -e $TESTENV
notifications: notifications:
irc: irc:

View File

@ -8,6 +8,7 @@ Andreas Zeidler
Andy Freeland Andy Freeland
Anthon van der Neut Anthon van der Neut
Armin Rigo Armin Rigo
Aron Curzon
Benjamin Peterson Benjamin Peterson
Bob Ippolito Bob Ippolito
Brian Dorsey Brian Dorsey

View File

@ -1,6 +1,9 @@
2.7.2 (compared to 2.7.1) 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. - fix issue713: JUnit XML reports for doctest failures.
Thanks Punyashloka Biswal. Thanks Punyashloka Biswal.

View File

@ -205,6 +205,9 @@ class LogXML(object):
self.suite_start_time = time.time() self.suite_start_time = time.time()
def pytest_sessionfinish(self): 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') logfile = open(self.logfile, 'w', encoding='utf-8')
suite_stop_time = time.time() suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time suite_time_delta = suite_stop_time - self.suite_start_time

View File

@ -3,6 +3,7 @@ text file.
""" """
import py import py
import os
def pytest_addoption(parser): def pytest_addoption(parser):
group = parser.getgroup("terminal reporting", "resultlog plugin options") group = parser.getgroup("terminal reporting", "resultlog plugin options")
@ -14,6 +15,9 @@ def pytest_configure(config):
resultlog = config.option.resultlog resultlog = config.option.resultlog
# prevent opening resultlog on slave nodes (xdist) # prevent opening resultlog on slave nodes (xdist)
if resultlog and not hasattr(config, 'slaveinput'): 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 logfile = open(resultlog, 'w', 1) # line buffered
config._resultlog = ResultLog(config, logfile) config._resultlog = ResultLog(config, logfile)
config.pluginmanager.register(config._resultlog) config.pluginmanager.register(config._resultlog)

View File

@ -474,6 +474,16 @@ def test_logxml_changingdir(testdir):
assert result.ret == 0 assert result.ret == 0
assert testdir.tmpdir.join("a/x.xml").check() 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): def test_escaped_parametrized_names_xml(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest

View File

@ -180,6 +180,21 @@ def test_generic(testdir, LineMatcher):
"x *:test_xfail_norun", "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): def test_no_resultlog_on_slaves(testdir):
config = testdir.parseconfig("-p", "resultlog", "--resultlog=resultlog") config = testdir.parseconfig("-p", "resultlog", "--resultlog=resultlog")

12
tox.ini
View File

@ -132,6 +132,18 @@ commands=
{envpython} runtests_setup.py build --build-exe build {envpython} runtests_setup.py build --build-exe build
{envpython} tox_run.py {envpython} tox_run.py
[testenv:coveralls]
changedir=testing
basepython=python3.4
deps =
{[testenv]deps}
coveralls
commands=
coverage run --source=_pytest {envdir}/bin/py.test
coverage report -m
coveralls
passenv=COVERALLS_REPO_TOKEN
[pytest] [pytest]
minversion=2.0 minversion=2.0
plugins=pytester plugins=pytester