Merge pull request #942 from RonnyPfannschmidt/adapt-print

Adapt plugin name printing
This commit is contained in:
Bruno Oliveira 2015-08-21 12:02:58 -03:00
commit 5f0e92a432
2 changed files with 38 additions and 9 deletions

View File

@ -298,13 +298,9 @@ class TerminalReporter:
plugininfo = config.pluginmanager.list_plugin_distinfo()
if plugininfo:
l = []
for plugin, dist in plugininfo:
name = dist.project_name
if name.startswith("pytest-"):
name = name[7:]
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):
@ -549,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

View File

@ -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