Add '--junit-suite-name' CLI option
This commit is contained in:
parent
b6125d9a13
commit
fe7d89f033
|
@ -226,13 +226,19 @@ def pytest_addoption(parser):
|
||||||
metavar="str",
|
metavar="str",
|
||||||
default=None,
|
default=None,
|
||||||
help="prepend prefix to classnames in junit-xml output")
|
help="prepend prefix to classnames in junit-xml output")
|
||||||
|
group.addoption(
|
||||||
|
'--junitsuitename', '--junit-suite-name',
|
||||||
|
action="store",
|
||||||
|
metavar="name",
|
||||||
|
default="pytest",
|
||||||
|
help="set the name attribute of root <testsuite> tag")
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
xmlpath = config.option.xmlpath
|
xmlpath = config.option.xmlpath
|
||||||
# prevent opening xmllog on slave nodes (xdist)
|
# prevent opening xmllog on slave nodes (xdist)
|
||||||
if xmlpath and not hasattr(config, 'slaveinput'):
|
if xmlpath and not hasattr(config, 'slaveinput'):
|
||||||
config._xml = LogXML(xmlpath, config.option.junitprefix)
|
config._xml = LogXML(xmlpath, config.option.junitprefix, config.option.junitsuitename)
|
||||||
config.pluginmanager.register(config._xml)
|
config.pluginmanager.register(config._xml)
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,10 +265,11 @@ def mangle_test_address(address):
|
||||||
|
|
||||||
|
|
||||||
class LogXML(object):
|
class LogXML(object):
|
||||||
def __init__(self, logfile, prefix):
|
def __init__(self, logfile, prefix, suite_name="pytest"):
|
||||||
logfile = os.path.expanduser(os.path.expandvars(logfile))
|
logfile = os.path.expanduser(os.path.expandvars(logfile))
|
||||||
self.logfile = os.path.normpath(os.path.abspath(logfile))
|
self.logfile = os.path.normpath(os.path.abspath(logfile))
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
self.suite_name = suite_name
|
||||||
self.stats = dict.fromkeys([
|
self.stats = dict.fromkeys([
|
||||||
'error',
|
'error',
|
||||||
'passed',
|
'passed',
|
||||||
|
@ -422,7 +429,7 @@ class LogXML(object):
|
||||||
logfile.write(Junit.testsuite(
|
logfile.write(Junit.testsuite(
|
||||||
self._get_global_properties_node(),
|
self._get_global_properties_node(),
|
||||||
[x.to_xml() for x in self.node_reporters_ordered],
|
[x.to_xml() for x in self.node_reporters_ordered],
|
||||||
name="pytest",
|
name=self.suite_name,
|
||||||
errors=self.stats['error'],
|
errors=self.stats['error'],
|
||||||
failures=self.stats['failure'],
|
failures=self.stats['failure'],
|
||||||
skips=self.stats['skipped'],
|
skips=self.stats['skipped'],
|
||||||
|
|
|
@ -617,6 +617,7 @@ def test_dont_configure_on_slaves(tmpdir):
|
||||||
self.option = self
|
self.option = self
|
||||||
|
|
||||||
junitprefix = None
|
junitprefix = None
|
||||||
|
junitsuitename = "pytest"
|
||||||
# XXX: shouldnt need tmpdir ?
|
# XXX: shouldnt need tmpdir ?
|
||||||
xmlpath = str(tmpdir.join('junix.xml'))
|
xmlpath = str(tmpdir.join('junix.xml'))
|
||||||
register = gotten.append
|
register = gotten.append
|
||||||
|
@ -1032,3 +1033,29 @@ def test_url_property(testdir):
|
||||||
test_case = minidom.parse(str(path)).getElementsByTagName('testcase')[0]
|
test_case = minidom.parse(str(path)).getElementsByTagName('testcase')[0]
|
||||||
|
|
||||||
assert (test_case.getAttribute('url') == test_url), "The URL did not get written to the xml"
|
assert (test_case.getAttribute('url') == test_url), "The URL did not get written to the xml"
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_suite_name(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_func():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result, dom = runandparse(testdir, '--junit-suite-name', "my_suite")
|
||||||
|
assert result.ret == 0
|
||||||
|
node = dom.find_first_by_tag("testsuite")
|
||||||
|
node.assert_attr(name="my_suite")
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_suite_name_default(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_func():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result, dom = runandparse(testdir)
|
||||||
|
assert result.ret == 0
|
||||||
|
node = dom.find_first_by_tag("testsuite")
|
||||||
|
node.assert_attr(name="pytest")
|
||||||
|
|
Loading…
Reference in New Issue