Disable sort on environment table when metadata is ordered
This commit is contained in:
parent
35a610065e
commit
fb6a456415
|
@ -96,6 +96,9 @@ via the :code:`pytest_configure` hook:
|
|||
def pytest_configure(config):
|
||||
config._metadata['foo'] = 'bar'
|
||||
|
||||
The generated table will be sorted alphabetically unless the metadata is a
|
||||
:code:`collections.OrderedDict`.
|
||||
|
||||
Additional summary information
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from base64 import b64encode, b64decode
|
||||
from collections import OrderedDict
|
||||
from os.path import isfile
|
||||
import datetime
|
||||
import json
|
||||
|
@ -465,7 +466,11 @@ class HTMLReport(object):
|
|||
environment = [html.h2('Environment')]
|
||||
rows = []
|
||||
|
||||
for key in [k for k in sorted(metadata.keys()) if metadata[k]]:
|
||||
keys = [k for k in metadata.keys() if metadata[k]]
|
||||
if not isinstance(metadata, OrderedDict):
|
||||
keys.sort()
|
||||
|
||||
for key in keys:
|
||||
value = metadata[key]
|
||||
if isinstance(value, basestring) and value.startswith('http'):
|
||||
value = html.a(value, href=value, target='_blank')
|
||||
|
|
|
@ -545,6 +545,18 @@ class TestHTML:
|
|||
assert 'Environment' in html
|
||||
assert len(re.findall(expected_html_re, html)) == 1
|
||||
|
||||
def test_environment_ordered(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
from collections import OrderedDict
|
||||
def pytest_configure(config):
|
||||
config._metadata = OrderedDict([('ZZZ', 1), ('AAA', 2)])
|
||||
""")
|
||||
testdir.makepyfile('def test_pass(): pass')
|
||||
result, html = run(testdir)
|
||||
assert result.ret == 0
|
||||
assert 'Environment' in html
|
||||
assert len(re.findall('ZZZ.+AAA', html, re.DOTALL)) == 1
|
||||
|
||||
@pytest.mark.xfail(
|
||||
sys.version_info < (3, 2) and
|
||||
LooseVersion(pytest.__version__) >= LooseVersion('2.8.0'),
|
||||
|
|
Loading…
Reference in New Issue