Improve rendering of collections in metadata (#132)

Render metadata collection values as comma seperated strings.
This commit is contained in:
Rasmus Pedersen 2017-09-19 10:04:34 +02:00 committed by Dave Hunt
parent ef6c05461a
commit 950b889108
2 changed files with 20 additions and 0 deletions

View File

@ -440,6 +440,8 @@ class HTMLReport(object):
value = metadata[key]
if isinstance(value, basestring) and value.startswith('http'):
value = html.a(value, href=value, target='_blank')
elif isinstance(value, (list, tuple, set)):
value = ', '.join((str(i) for i in value))
rows.append(html.tr(html.td(key), html.td(value)))
environment.append(html.table(rows, id='environment'))

View File

@ -490,6 +490,24 @@ class TestHTML:
assert 'Environment' in html
assert len(re.findall(content, html)) == 1
def test_environment_list_value(self, testdir):
content = tuple(str(random.random()) for i in range(10))
content += tuple(random.random() for i in range(10))
expected_content = ', '.join((str(i) for i in content))
expected_html_re = '<td>content</td>\n\s+<td>{}</td>'.format(
expected_content
)
testdir.makeconftest("""
def pytest_configure(config):
for i in range(2):
config._metadata['content'] = {0}
""".format(content))
testdir.makepyfile('def test_pass(): pass')
result, html = run(testdir)
assert result.ret == 0
assert 'Environment' in html
assert len(re.findall(expected_html_re, html)) == 1
@pytest.mark.xfail(
sys.version_info < (3, 2) and
LooseVersion(pytest.__version__) >= LooseVersion('2.8.0'),