From 2c42f15e004226eb7b3fff917affb1cfbb8ca4aa Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 8 Aug 2015 09:27:16 +0200 Subject: [PATCH 1/3] adapt plugin printing * print each distribution only once(xdist now has 3 entrypoints) * include the distribution version --- _pytest/terminal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 5365b4300..54d2660ff 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -300,10 +300,15 @@ class TerminalReporter: if plugininfo: l = [] for plugin, dist in plugininfo: - name = dist.project_name + # gets us name and version! + name = str(dist) + # questionable convenience, but it keeps things short if name.startswith("pytest-"): name = name[7:] - l.append(name) + # we decided to print python package names + # they can have more than one plugin + if name not in l: + l.append(name) lines.append("plugins: %s" % ", ".join(l)) return lines From 740a97a8cc185df9f5903bfaf141d725be3dde6c Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 17 Aug 2015 08:48:38 +0200 Subject: [PATCH 2/3] terinalwriter: use dash between plugin name and version --- _pytest/terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 54d2660ff..0d8261e83 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -301,7 +301,7 @@ class TerminalReporter: l = [] for plugin, dist in plugininfo: # gets us name and version! - name = str(dist) + name = '{dist.project_name}-{dist.version}'.format(dist=dist) # questionable convenience, but it keeps things short if name.startswith("pytest-"): name = name[7:] From 7758bcd141275bb1856dba2fa0ed09e2feacacd8 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 17 Aug 2015 09:10:01 +0200 Subject: [PATCH 3/3] terminalwriter: extract plugin printing logic and add positive unittests --- _pytest/terminal.py | 30 ++++++++++++++++++------------ testing/test_terminal.py | 22 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 0d8261e83..e3ca23533 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -298,18 +298,9 @@ class TerminalReporter: plugininfo = config.pluginmanager.list_plugin_distinfo() if plugininfo: - l = [] - for plugin, dist in plugininfo: - # gets us name and version! - name = '{dist.project_name}-{dist.version}'.format(dist=dist) - # questionable convenience, but it keeps things short - if name.startswith("pytest-"): - name = name[7:] - # we decided to print python package names - # they can have more than one plugin - if name not in l: - l.append(name) - lines.append("plugins: %s" % ", ".join(l)) + + lines.append( + "plugins: %s" % ", ".join(_plugin_nameversions(plugininfo))) return lines def pytest_collection_finish(self, session): @@ -554,3 +545,18 @@ def build_summary_stats_line(stats): color = 'yellow' return (line, color) + + +def _plugin_nameversions(plugininfo): + l = [] + for plugin, dist in plugininfo: + # gets us name and version! + name = '{dist.project_name}-{dist.version}'.format(dist=dist) + # questionable convenience, but it keeps things short + if name.startswith("pytest-"): + name = name[7:] + # we decided to print python package names + # they can have more than one plugin + if name not in l: + l.append(name) + return l diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 7ad74a921..50c27509f 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1,19 +1,23 @@ """ terminal reporting of the full testing process. """ +import collections import pytest import py import pluggy import sys from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt -from _pytest.terminal import build_summary_stats_line +from _pytest.terminal import build_summary_stats_line, _plugin_nameversions from _pytest import runner def basic_run_report(item): runner.call_and_report(item, "setup", log=False) return runner.call_and_report(item, "call", log=False) +DistInfo = collections.namedtuple('DistInfo', ['project_name', 'version']) + + class Option: def __init__(self, verbose=False, fulltrace=False): self.verbose = verbose @@ -40,6 +44,21 @@ def pytest_generate_tests(metafunc): funcargs={'option': Option(fulltrace=True)}) +@pytest.mark.parametrize('input,expected', [ + ([DistInfo(project_name='test', version=1)], ['test-1']), + ([DistInfo(project_name='pytest-test', version=1)], ['test-1']), + ([ + DistInfo(project_name='test', version=1), + DistInfo(project_name='test', version=1) + ], ['test-1']), +], ids=['normal', 'prefix-strip', 'deduplicate']) + +def test_plugin_nameversion(input, expected): + pluginlist = [(None, x) for x in input] + result = _plugin_nameversions(pluginlist) + assert result == expected + + class TestTerminal: def test_pass_skip_fail(self, testdir, option): testdir.makepyfile(""" @@ -783,4 +802,3 @@ def test_summary_stats(exp_line, exp_color, stats_arg): print("Actually got: \"%s\"; with color \"%s\"" % (line, color)) assert line == exp_line assert color == exp_color -