Skip to content

Commit 950b889

Browse files
rasmuspeders1davehunt
authored andcommitted
Improve rendering of collections in metadata (#132)
Render metadata collection values as comma seperated strings.
1 parent ef6c054 commit 950b889

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

pytest_html/plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ def _generate_environment(self, config):
440440
value = metadata[key]
441441
if isinstance(value, basestring) and value.startswith('http'):
442442
value = html.a(value, href=value, target='_blank')
443+
elif isinstance(value, (list, tuple, set)):
444+
value = ', '.join((str(i) for i in value))
443445
rows.append(html.tr(html.td(key), html.td(value)))
444446

445447
environment.append(html.table(rows, id='environment'))

testing/test_pytest_html.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,24 @@ def pytest_configure(config):
490490
assert 'Environment' in html
491491
assert len(re.findall(content, html)) == 1
492492

493+
def test_environment_list_value(self, testdir):
494+
content = tuple(str(random.random()) for i in range(10))
495+
content += tuple(random.random() for i in range(10))
496+
expected_content = ', '.join((str(i) for i in content))
497+
expected_html_re = '<td>content</td>\n\s+<td>{}</td>'.format(
498+
expected_content
499+
)
500+
testdir.makeconftest("""
501+
def pytest_configure(config):
502+
for i in range(2):
503+
config._metadata['content'] = {0}
504+
""".format(content))
505+
testdir.makepyfile('def test_pass(): pass')
506+
result, html = run(testdir)
507+
assert result.ret == 0
508+
assert 'Environment' in html
509+
assert len(re.findall(expected_html_re, html)) == 1
510+
493511
@pytest.mark.xfail(
494512
sys.version_info < (3, 2) and
495513
LooseVersion(pytest.__version__) >= LooseVersion('2.8.0'),

0 commit comments

Comments
 (0)