Skip to content

Commit c5a8263

Browse files
authored
Sync .pre-commit-config.yaml with pytest (#335)
1 parent 8d45718 commit c5a8263

File tree

5 files changed

+86
-43
lines changed

5 files changed

+86
-43
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: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
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-
12+
from base64 import b64decode
13+
from base64 import b64encode
14+
from collections import OrderedDict
15+
from functools import lru_cache
1916
from html import escape
20-
import pytest
17+
from os.path import isfile
2118

22-
from py.xml import html, raw
19+
import pkg_resources
20+
import pytest
21+
from _pytest.logging import _remove_ansi_escape_sequences
22+
from py.xml import html
23+
from py.xml import raw
2324

25+
from . import __pypi_url__
26+
from . import __version__
2427
from . import extras
25-
from . import __version__, __pypi_url__
26-
27-
from _pytest.logging import _remove_ansi_escape_sequences
2828

2929

3030
@lru_cache()
@@ -88,7 +88,7 @@ def pytest_configure(config):
8888
if htmlpath:
8989
for csspath in config.getoption("css"):
9090
if not os.path.exists(csspath):
91-
raise IOError(f"No such file or directory: '{csspath}'")
91+
raise OSError(f"No such file or directory: '{csspath}'")
9292
if not hasattr(config, "workerinput"):
9393
# prevent opening htmlpath on worker nodes (xdist)
9494
config._html = HTMLReport(htmlpath, config)
@@ -119,8 +119,10 @@ def extra(pytestconfig):
119119
.. code-block:: python
120120
121121
import pytest_html
122+
123+
122124
def test_foo(extra):
123-
extra.append(pytest_html.extras.url('http://www.example.com/'))
125+
extra.append(pytest_html.extras.url("http://www.example.com/"))
124126
"""
125127
pytestconfig.extras = []
126128
yield pytestconfig.extras
@@ -434,7 +436,7 @@ def _generate_report(self, session):
434436
self.style_css += "\n * CUSTOM CSS"
435437
self.style_css += f"\n * {path}"
436438
self.style_css += "\n ******************************/\n\n"
437-
with open(path, "r") as f:
439+
with open(path) as f:
438440
self.style_css += f.read()
439441

440442
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)