Skip to content

Commit bff6bcd

Browse files
committed
merge
2 parents 78a96d6 + c5a8263 commit bff6bcd

File tree

5 files changed

+88
-44
lines changed

5 files changed

+88
-44
lines changed

.pre-commit-config.yaml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
11
repos:
2-
32
- repo: https://github.com/psf/black
4-
rev: stable
3+
rev: 19.10b0
54
hooks:
65
- id: black
76
args: [--safe, --quiet]
7+
- repo: https://github.com/asottile/blacken-docs
8+
rev: v1.7.0
9+
hooks:
10+
- id: blacken-docs
11+
additional_dependencies: [black==19.10b0]
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v3.1.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: end-of-file-fixer
17+
- id: fix-encoding-pragma
18+
args: [--remove]
19+
- id: check-yaml
20+
- id: debug-statements
821
language_version: python3
9-
1022
- repo: https://gitlab.com/pycqa/flake8
11-
rev: 3.7.7
23+
rev: 3.8.2
1224
hooks:
1325
- id: flake8
14-
exclude: docs
1526
language_version: python3
27+
additional_dependencies:
28+
- flake8-typing-imports==1.9.0
29+
- repo: https://github.com/asottile/reorder_python_imports
30+
rev: v2.3.0
31+
hooks:
32+
- id: reorder-python-imports
33+
args: ['--application-directories=.:pytest_html:testing', --py3-plus]
34+
- repo: https://github.com/asottile/pyupgrade
35+
rev: v2.4.4
36+
hooks:
37+
- id: pyupgrade
38+
args: [--py3-plus]
39+
- repo: local
40+
hooks:
41+
- id: rst
42+
name: rst
43+
entry: rst-lint --encoding utf-8
44+
files: ^(CHANGES.rst|development.rst|README.rst)$
45+
language: python
46+
additional_dependencies: [pygments, restructuredtext_lint]

README.rst

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ By default report title will be the filename of the report, you can edit it by u
9797
import pytest
9898
from py.xml import html
9999
100-
def pytest_html_report_title(report)
101-
report.title = "My very own title!"
100+
101+
def pytest_html_report_title(report):
102+
report.title = "My very own title!"
102103
103104
Environment
104105
~~~~~~~~~~~
@@ -110,7 +111,7 @@ via the :code:`pytest_configure` hook:
110111
.. code-block:: python
111112
112113
def pytest_configure(config):
113-
config._metadata['foo'] = 'bar'
114+
config._metadata["foo"] = "bar"
114115
115116
The generated table will be sorted alphabetically unless the metadata is a
116117
:code:`collections.OrderedDict`.
@@ -125,6 +126,7 @@ You can edit the *Summary* section by using the :code:`pytest_html_results_summa
125126
import pytest
126127
from py.xml import html
127128
129+
128130
def pytest_html_results_summary(prefix, summary, postfix):
129131
prefix.extend([html.p("foo: bar")])
130132
@@ -170,27 +172,29 @@ conftest.py file:
170172
.. code-block:: python
171173
172174
import pytest
175+
176+
173177
@pytest.hookimpl(hookwrapper=True)
174178
def pytest_runtest_makereport(item, call):
175-
pytest_html = item.config.pluginmanager.getplugin('html')
179+
pytest_html = item.config.pluginmanager.getplugin("html")
176180
outcome = yield
177181
report = outcome.get_result()
178-
extra = getattr(report, 'extra', [])
179-
if report.when == 'call':
182+
extra = getattr(report, "extra", [])
183+
if report.when == "call":
180184
# always add url to report
181-
extra.append(pytest_html.extras.url('http://www.example.com/'))
182-
xfail = hasattr(report, 'wasxfail')
185+
extra.append(pytest_html.extras.url("http://www.example.com/"))
186+
xfail = hasattr(report, "wasxfail")
183187
if (report.skipped and xfail) or (report.failed and not xfail):
184188
# only add additional html on failure
185-
extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
189+
extra.append(pytest_html.extras.html("<div>Additional HTML</div>"))
186190
report.extra = extra
187191
188192
You can also specify the :code:`name` argument for all types other than :code:`html` which will change the title of the
189193
created hyper link:
190194

191195
.. code-block:: python
192196
193-
extra.append(pytest_html.extras.text('some string', name='Different title'))
197+
extra.append(pytest_html.extras.text("some string", name="Different title"))
194198
195199
It is also possible to use the fixture :code:`extra` to add content directly
196200
in a test function without implementing hooks. These will generally end up
@@ -200,8 +204,9 @@ before any extras added by plugins.
200204
201205
from pytest_html import extras
202206
207+
203208
def test_extra(extra):
204-
extra.append(extras.text('some string'))
209+
extra.append(extras.text("some string"))
205210
206211
207212
Modifying the results table
@@ -218,16 +223,19 @@ column:
218223
from py.xml import html
219224
import pytest
220225
226+
221227
def pytest_html_results_table_header(cells):
222-
cells.insert(2, html.th('Description'))
223-
cells.insert(1, html.th('Time', class_='sortable time', col='time'))
228+
cells.insert(2, html.th("Description"))
229+
cells.insert(1, html.th("Time", class_="sortable time", col="time"))
224230
cells.pop()
225231
232+
226233
def pytest_html_results_table_row(report, cells):
227234
cells.insert(2, html.td(report.description))
228-
cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
235+
cells.insert(1, html.td(datetime.utcnow(), class_="col-time"))
229236
cells.pop()
230237
238+
231239
@pytest.hookimpl(hookwrapper=True)
232240
def pytest_runtest_makereport(item, call):
233241
outcome = yield
@@ -242,9 +250,10 @@ following example removes all passed results from the report:
242250
243251
import pytest
244252
253+
245254
def pytest_html_results_table_row(report, cells):
246255
if report.passed:
247-
del cells[:]
256+
del cells[:]
248257
249258
The log output and additional HTML can be modified by implementing the
250259
:code:`pytest_html_results_html` hook. The following example replaces all
@@ -254,10 +263,11 @@ additional HTML and log output with a notice that the log is empty:
254263
255264
import pytest
256265
266+
257267
def pytest_html_results_table_html(report, data):
258268
if report.passed:
259269
del data[:]
260-
data.append(html.div('No log output captured.', class_='empty log'))
270+
data.append(html.div("No log output captured.", class_="empty log"))
261271
262272
Display options
263273
---------------

pytest_html/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from pkg_resources import get_distribution, DistributionNotFound
1+
from pkg_resources import DistributionNotFound
2+
from pkg_resources import get_distribution
23

34

45
try:

pytest_html/plugin.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
5-
from base64 import b64encode, b64decode
6-
from collections import OrderedDict
7-
from functools import lru_cache
8-
import importlib
9-
from os.path import isfile
4+
import bisect
105
import datetime
6+
import importlib
117
import json
128
import os
13-
import pkg_resources
9+
import re
1410
import time
15-
import bisect
1611
import warnings
17-
import re
18-
import collections
1912

13+
from base64 import b64decode
14+
from base64 import b64encode
15+
from collections import defaultdict
16+
from collections import OrderedDict
17+
from functools import lru_cache
2018
from html import escape
21-
import pytest
19+
from os.path import isfile
2220

23-
from py.xml import html, raw
21+
import pkg_resources
22+
import pytest
23+
from _pytest.logging import _remove_ansi_escape_sequences
24+
from py.xml import html
25+
from py.xml import raw
2426

27+
from . import __pypi_url__
28+
from . import __version__
2529
from . import extras
26-
from . import __version__, __pypi_url__
27-
28-
from _pytest.logging import _remove_ansi_escape_sequences
2930

3031

3132
@lru_cache()
@@ -89,7 +90,7 @@ def pytest_configure(config):
8990
if htmlpath:
9091
for csspath in config.getoption("css"):
9192
if not os.path.exists(csspath):
92-
raise IOError(f"No such file or directory: '{csspath}'")
93+
raise OSError(f"No such file or directory: '{csspath}'")
9394
if not hasattr(config, "workerinput"):
9495
# prevent opening htmlpath on worker nodes (xdist)
9596
config._html = HTMLReport(htmlpath, config)
@@ -120,8 +121,10 @@ def extra(pytestconfig):
120121
.. code-block:: python
121122
122123
import pytest_html
124+
125+
123126
def test_foo(extra):
124-
extra.append(pytest_html.extras.url('http://www.example.com/'))
127+
extra.append(pytest_html.extras.url("http://www.example.com/"))
125128
"""
126129
pytestconfig.extras = []
127130
yield pytestconfig.extras
@@ -147,7 +150,7 @@ def __init__(self, logfile, config):
147150
self.rerun = 0 if has_rerun else None
148151
self.self_contained = config.getoption("self_contained_html")
149152
self.config = config
150-
self.reports = collections.defaultdict(list)
153+
self.reports = defaultdict(list)
151154

152155
class TestResult:
153156
def __init__(self, outcome, report, logfile, config):
@@ -441,7 +444,7 @@ def _generate_report(self, session):
441444
self.style_css += "\n * CUSTOM CSS"
442445
self.style_css += f"\n * {path}"
443446
self.style_css += "\n ******************************/\n\n"
444-
with open(path, "r") as f:
447+
with open(path) as f:
445448
self.style_css += f.read()
446449

447450
css_href = "assets/style.css"

testing/test_pytest_html.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
5-
from base64 import b64encode
64
import json
75
import os
8-
import pkg_resources
96
import random
107
import re
8+
from base64 import b64encode
119

10+
import pkg_resources
1211
import pytest
1312

1413
pytest_plugins = ("pytester",)

0 commit comments

Comments
 (0)