Restore environment heading, fix tests, and document pytest-metadata changes
This commit is contained in:
parent
b5b3e26906
commit
a1413ed734
10
README.rst
10
README.rst
|
@ -71,14 +71,14 @@ Enhancing reports
|
|||
Environment
|
||||
~~~~~~~~~~~
|
||||
|
||||
You can add change the *Environment* section of the report by modifying
|
||||
``request.config._html.environment`` from a fixture:
|
||||
The *Environment* section is provided by the `pytest-metadata
|
||||
<https://pypi.python.org/pypi/pytest-metadata/>`_, plugin, and can be accessed
|
||||
via the :code:`pytest_configure` hook:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _environment(request):
|
||||
request.config._environment.append(('foo', 'bar'))
|
||||
def pytest_configure(config):
|
||||
config._metadata['foo'] = 'bar'
|
||||
|
||||
Extra content
|
||||
~~~~~~~~~~~~~
|
||||
|
|
|
@ -393,7 +393,7 @@ class HTMLReport(object):
|
|||
' v{0}'.format(__version__)),
|
||||
onLoad='init()')
|
||||
|
||||
body.extend(self._generate_metadata(session.config))
|
||||
body.extend(self._generate_environment(session.config))
|
||||
body.extend(summary)
|
||||
body.extend(results)
|
||||
|
||||
|
@ -407,13 +407,16 @@ class HTMLReport(object):
|
|||
unicode_doc = unicode_doc.decode('utf-8')
|
||||
return unicode_doc
|
||||
|
||||
def _generate_metadata(self, config):
|
||||
metadata = [html.h2('Metadata')]
|
||||
rows = []
|
||||
d = config._metadata
|
||||
def _generate_environment(self, config):
|
||||
if not hasattr(config, '_metadata') or config._metadata is None:
|
||||
return []
|
||||
|
||||
for key in [k for k in sorted(d.keys()) if d[k]]:
|
||||
value = d[key]
|
||||
metadata = config._metadata
|
||||
environment = [html.h2('Environment')]
|
||||
rows = []
|
||||
|
||||
for key in [k for k in sorted(metadata.keys()) if metadata[k]]:
|
||||
value = metadata[key]
|
||||
if isinstance(value, basestring) and value.startswith('http'):
|
||||
value = html.a(value, href=value, target='_blank')
|
||||
elif not isinstance(value, basestring):
|
||||
|
@ -425,8 +428,8 @@ class HTMLReport(object):
|
|||
value = ', '.join(value)
|
||||
rows.append(html.tr(html.td(key), html.td(value)))
|
||||
|
||||
metadata.append(html.table(rows, id='metadata'))
|
||||
return metadata
|
||||
environment.append(html.table(rows, id='environment'))
|
||||
return environment
|
||||
|
||||
def _save_report(self, report_content):
|
||||
dir_name = os.path.dirname(self.logfile)
|
||||
|
|
|
@ -25,12 +25,12 @@ table {
|
|||
* SUMMARY INFORMATION
|
||||
******************************/
|
||||
|
||||
#metadata td {
|
||||
#environment td {
|
||||
padding: 5px;
|
||||
border: 1px solid #E6E6E6;
|
||||
}
|
||||
|
||||
#metadata tr:nth-child(odd) {
|
||||
#environment tr:nth-child(odd) {
|
||||
background-color: #f6f6f6;
|
||||
}
|
||||
|
||||
|
|
|
@ -421,10 +421,8 @@ class TestHTML:
|
|||
|
||||
def test_no_environment(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
@pytest.fixture(autouse=True)
|
||||
def _environment(request):
|
||||
request.config._environment = None
|
||||
def pytest_configure(config):
|
||||
config._metadata = None
|
||||
""")
|
||||
testdir.makepyfile('def test_pass(): pass')
|
||||
result, html = run(testdir)
|
||||
|
@ -434,11 +432,8 @@ class TestHTML:
|
|||
def test_environment(self, testdir):
|
||||
content = str(random.random())
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
@pytest.fixture(autouse=True)
|
||||
def _environment(request):
|
||||
for i in range(2):
|
||||
request.config._environment.append(('content', '{0}'))
|
||||
def pytest_configure(config):
|
||||
config._metadata['content'] = '{0}'
|
||||
""".format(content))
|
||||
testdir.makepyfile('def test_pass(): pass')
|
||||
result, html = run(testdir)
|
||||
|
@ -449,11 +444,9 @@ class TestHTML:
|
|||
def test_environment_xdist(self, testdir):
|
||||
content = str(random.random())
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
@pytest.fixture(autouse=True)
|
||||
def _environment(request):
|
||||
def pytest_configure(config):
|
||||
for i in range(2):
|
||||
request.config._environment.append(('content', '{0}'))
|
||||
config._metadata['content'] = '{0}'
|
||||
""".format(content))
|
||||
testdir.makepyfile('def test_pass(): pass')
|
||||
result, html = run(testdir, 'report.html', '-n', '1')
|
||||
|
@ -464,11 +457,9 @@ class TestHTML:
|
|||
def test_environment_xdist_reruns(self, testdir):
|
||||
content = str(random.random())
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
@pytest.fixture(autouse=True)
|
||||
def _environment(request):
|
||||
def pytest_configure(config):
|
||||
for i in range(2):
|
||||
request.config._environment.append(('content', '{0}'))
|
||||
config._metadata['content'] = '{0}'
|
||||
""".format(content))
|
||||
testdir.makepyfile('def test_fail(): assert False')
|
||||
result, html = run(testdir, 'report.html', '-n', '1', '--reruns', '1')
|
||||
|
|
Loading…
Reference in New Issue