From 8bcf88ec121215788b5edcd8fd6da8f8c15e6432 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 5 May 2017 11:16:05 +0200 Subject: [PATCH 1/8] try to consider all modules after registration as plugin --- _pytest/config.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index 7c8fad79f..0a79cb5b1 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -8,7 +8,8 @@ import warnings import py # DON't import pytest here because it causes import cycle troubles -import sys, os +import sys +import os import _pytest._code import _pytest.hookspec # the extension point definitions import _pytest.assertion @@ -252,6 +253,9 @@ class PytestPluginManager(PluginManager): if ret: self.hook.pytest_plugin_registered.call_historic( kwargs=dict(plugin=plugin, manager=self)) + + if isinstance(plugin, types.ModuleType): + self.consider_module(plugin) return ret def getplugin(self, name): @@ -396,8 +400,7 @@ class PytestPluginManager(PluginManager): self.import_plugin(arg) def consider_conftest(self, conftestmodule): - if self.register(conftestmodule, name=conftestmodule.__file__): - self.consider_module(conftestmodule) + self.register(conftestmodule, name=conftestmodule.__file__) def consider_env(self): self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS")) @@ -441,7 +444,6 @@ class PytestPluginManager(PluginManager): else: mod = sys.modules[importspec] self.register(mod, modname) - self.consider_module(mod) def _get_plugin_specs_as_list(specs): From a92e397011c02d0a6f336812934750fd95688058 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 12 May 2017 18:39:45 +0200 Subject: [PATCH 2/8] add changelog for fixing #2391 --- CHANGELOG.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b71152cd8..3f4814d8e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -81,6 +81,8 @@ Changes * fix `#2308`_: When using both ``--lf`` and ``--ff``, only the last failed tests are run. Thanks `@ojii`_ for the PR. +* fix `#2391`_: consider pytest_plugins on all plugin modules + Thansks `@RonnyPfannschmidt`_ for the PR. Bug Fixes --------- @@ -114,8 +116,9 @@ Bug Fixes .. _#2166: https://github.com/pytest-dev/pytest/pull/2166 .. _#2147: https://github.com/pytest-dev/pytest/issues/2147 .. _#2208: https://github.com/pytest-dev/pytest/issues/2208 -.. _#2228: https://github.com/pytest-dev/pytest/issues/2228 +.. _#2228: https://github.com/pytest-dev/pytest/issues/2228 .. _#2308: https://github.com/pytest-dev/pytest/issues/2308 +.. _#2391: https://github.com/pytest-dev/pytest/issues/2391 3.0.8 (unreleased) From fe7d89f03370d087769c6093d7dac70f83160e0c Mon Sep 17 00:00:00 2001 From: Dmitri Pribysh Date: Wed, 22 Feb 2017 23:31:30 +0300 Subject: [PATCH 3/8] Add '--junit-suite-name' CLI option --- _pytest/junitxml.py | 13 ++++++++++--- testing/test_junitxml.py | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 4bd334a16..5240e0e28 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -226,13 +226,19 @@ def pytest_addoption(parser): metavar="str", default=None, 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 tag") def pytest_configure(config): xmlpath = config.option.xmlpath # prevent opening xmllog on slave nodes (xdist) 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) @@ -259,10 +265,11 @@ def mangle_test_address(address): class LogXML(object): - def __init__(self, logfile, prefix): + def __init__(self, logfile, prefix, suite_name="pytest"): logfile = os.path.expanduser(os.path.expandvars(logfile)) self.logfile = os.path.normpath(os.path.abspath(logfile)) self.prefix = prefix + self.suite_name = suite_name self.stats = dict.fromkeys([ 'error', 'passed', @@ -422,7 +429,7 @@ class LogXML(object): logfile.write(Junit.testsuite( self._get_global_properties_node(), [x.to_xml() for x in self.node_reporters_ordered], - name="pytest", + name=self.suite_name, errors=self.stats['error'], failures=self.stats['failure'], skips=self.stats['skipped'], diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 7003d9f5f..417f8cca6 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -617,6 +617,7 @@ def test_dont_configure_on_slaves(tmpdir): self.option = self junitprefix = None + junitsuitename = "pytest" # XXX: shouldnt need tmpdir ? xmlpath = str(tmpdir.join('junix.xml')) register = gotten.append @@ -1032,3 +1033,29 @@ def test_url_property(testdir): 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" + + +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") From 204db4d1e20032f986730c6e9844d22f310c51c8 Mon Sep 17 00:00:00 2001 From: Dmitri Pribysh Date: Wed, 22 Feb 2017 23:31:37 +0300 Subject: [PATCH 4/8] Update Changelog --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b71152cd8..d408ff551 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,8 @@ New Features ------------ +* junitxml: Add `--junit-suite-name` option to specify root `` name for JUnit XML reports + * Added an ini option ``doctest_encoding`` to specify which encoding to use for doctest files. Thanks `@wheerd`_ for the PR (`#2101`_). From bcfa6264f114f574bc7870c5fb50752db8da9349 Mon Sep 17 00:00:00 2001 From: Dmitri Pribysh Date: Wed, 22 Feb 2017 23:31:45 +0300 Subject: [PATCH 5/8] Update AUTHORS list --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index f3dafb999..90e639234 100644 --- a/AUTHORS +++ b/AUTHORS @@ -48,6 +48,7 @@ David Vierra Denis Kirisov Diego Russo Dmitry Dygalo +Dmitry Pribysh Duncan Betts Edison Gustavo Muenz Edoardo Batini From c9282f9e948a928dabfafa3b217ebb006a8ac223 Mon Sep 17 00:00:00 2001 From: Dmitri Pribysh Date: Fri, 12 May 2017 04:45:20 +0300 Subject: [PATCH 6/8] Transition to using ini option for suite name --- _pytest/junitxml.py | 9 ++------- testing/test_junitxml.py | 5 +++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 5240e0e28..301633706 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -226,19 +226,14 @@ def pytest_addoption(parser): metavar="str", default=None, 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 tag") + parser.addini("junit_suite_name", "Test suite name for JUnit report", default="pytest") def pytest_configure(config): xmlpath = config.option.xmlpath # prevent opening xmllog on slave nodes (xdist) if xmlpath and not hasattr(config, 'slaveinput'): - config._xml = LogXML(xmlpath, config.option.junitprefix, config.option.junitsuitename) + config._xml = LogXML(xmlpath, config.option.junitprefix, config.getini("junit_suite_name")) config.pluginmanager.register(config._xml) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 417f8cca6..9735f45ef 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -616,8 +616,9 @@ def test_dont_configure_on_slaves(tmpdir): self.pluginmanager = self self.option = self + getini = lambda self, name: "pytest" + junitprefix = None - junitsuitename = "pytest" # XXX: shouldnt need tmpdir ? xmlpath = str(tmpdir.join('junix.xml')) register = gotten.append @@ -1042,7 +1043,7 @@ def test_set_suite_name(testdir): def test_func(): pass """) - result, dom = runandparse(testdir, '--junit-suite-name', "my_suite") + result, dom = runandparse(testdir, '-o', "junit_suite_name=my_suite") assert result.ret == 0 node = dom.find_first_by_tag("testsuite") node.assert_attr(name="my_suite") From 2ab8d12fe3ebed9716786408798da7e25789b8af Mon Sep 17 00:00:00 2001 From: Dmitri Pribysh Date: Fri, 12 May 2017 04:54:15 +0300 Subject: [PATCH 7/8] Update changelog and add usage info --- CHANGELOG.rst | 3 ++- doc/en/usage.rst | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d408ff551..bdacbed89 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ New Features ------------ -* junitxml: Add `--junit-suite-name` option to specify root `` name for JUnit XML reports +* fix `#533`_: Added ``junit_suite_name`` ini option to specify root `` name for JUnit XML reports * Added an ini option ``doctest_encoding`` to specify which encoding to use for doctest files. Thanks `@wheerd`_ for the PR (`#2101`_). @@ -105,6 +105,7 @@ Bug Fixes .. _@ojii: https://github.com/ojii +.. _#533: https://github.com/pytest-dev/pytest/issues/533 .. _#1407: https://github.com/pytest-dev/pytest/issues/1407 .. _#1512: https://github.com/pytest-dev/pytest/issues/1512 .. _#1821: https://github.com/pytest-dev/pytest/issues/1821 diff --git a/doc/en/usage.rst b/doc/en/usage.rst index f6c20a978..763328f5a 100644 --- a/doc/en/usage.rst +++ b/doc/en/usage.rst @@ -177,6 +177,15 @@ integration servers, use this invocation:: to create an XML file at ``path``. +.. versionadded:: 3.1 + +To set the name of the root test suite xml item, you can configure the ``junit_suite_name`` option in your config file: + +.. code-block:: ini + + [pytest] + junit_suite_name = my_suite + record_xml_property ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From f39f416c5d84530f6839b9ea7a3c5303a61329f8 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 12 May 2017 17:52:50 -0300 Subject: [PATCH 8/8] Improve tests a bit Use a normal function instead of a lambda Parametrize test about suite name option --- testing/test_junitxml.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 9735f45ef..bc637b035 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -616,7 +616,8 @@ def test_dont_configure_on_slaves(tmpdir): self.pluginmanager = self self.option = self - getini = lambda self, name: "pytest" + def getini(self, name): + return "pytest" junitprefix = None # XXX: shouldnt need tmpdir ? @@ -1036,20 +1037,16 @@ def test_url_property(testdir): 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, '-o', "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): +@pytest.mark.parametrize('suite_name', ['my_suite', '']) +def test_set_suite_name(testdir, suite_name): + if suite_name: + testdir.makeini(""" + [pytest] + junit_suite_name={0} + """.format(suite_name)) + expected = suite_name + else: + expected = 'pytest' testdir.makepyfile(""" import pytest @@ -1059,4 +1056,5 @@ def test_set_suite_name_default(testdir): result, dom = runandparse(testdir) assert result.ret == 0 node = dom.find_first_by_tag("testsuite") - node.assert_attr(name="pytest") + node.assert_attr(name=expected) +