Skip to content

Commit 4f1f537

Browse files
committed
Chore: Assorted fixes around pytest entry points
1 parent f2cf3b2 commit 4f1f537

File tree

10 files changed

+77
-45
lines changed

10 files changed

+77
-45
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ jobs:
7878
}}
7979
uses: codecov/codecov-action@v3
8080
with:
81-
fail_ci_if_error: true
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
fail_ci_if_error: false
8283
files: ./cobertura-coverage.xml
8384
flags: js_tests
8485
name: ubuntu-latest-node-16
@@ -163,7 +164,8 @@ jobs:
163164
}}
164165
uses: codecov/codecov-action@v3
165166
with:
166-
fail_ci_if_error: true
167+
token: ${{ secrets.CODECOV_TOKEN }}
168+
fail_ci_if_error: false
167169
files: ./coverage.xml
168170
flags: py_unit_tests
169171
name: ${{ matrix.os }}-python-${{ matrix.python-version }}
@@ -236,7 +238,8 @@ jobs:
236238
}}
237239
uses: codecov/codecov-action@v3
238240
with:
239-
fail_ci_if_error: true
241+
token: ${{ secrets.CODECOV_TOKEN }}
242+
fail_ci_if_error: false
240243
files: ./coverage.xml
241244
flags: py_integration_tests
242245
name: ubuntu-latest-${{ matrix.python-version }}

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Source = "https://github.com/pytest-dev/pytest-html"
7070

7171
[project.entry-points.pytest11]
7272
html = "pytest_html.plugin"
73+
html_fixtures = "pytest_html.fixtures"
7374

7475
[tool.hatch.envs.test]
7576
features = [

src/pytest_html/basereport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
14
import datetime
25
import json
36
import os

src/pytest_html/fixtures.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
import warnings
5+
6+
import pytest
7+
8+
extras_stash_key = pytest.StashKey[list]()
9+
10+
11+
@pytest.fixture
12+
def extra(pytestconfig):
13+
"""DEPRECATED: Add details to the HTML reports.
14+
15+
.. code-block:: python
16+
17+
import pytest_html
18+
19+
20+
def test_foo(extra):
21+
extra.append(pytest_html.extras.url("https://www.example.com/"))
22+
"""
23+
warnings.warn(
24+
"The 'extra' fixture is deprecated and will be removed in a future release"
25+
", use 'extras' instead.",
26+
DeprecationWarning,
27+
)
28+
pytestconfig.stash[extras_stash_key] = []
29+
yield pytestconfig.stash[extras_stash_key]
30+
del pytestconfig.stash[extras_stash_key][:]
31+
32+
33+
@pytest.fixture
34+
def extras(pytestconfig):
35+
"""Add details to the HTML reports.
36+
37+
.. code-block:: python
38+
39+
import pytest_html
40+
41+
42+
def test_foo(extras):
43+
extras.append(pytest_html.extras.url("https://www.example.com/"))
44+
"""
45+
pytestconfig.stash[extras_stash_key] = []
46+
yield pytestconfig.stash[extras_stash_key]
47+
del pytestconfig.stash[extras_stash_key][:]

src/pytest_html/plugin.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
import pytest
88

9-
from pytest_html.basereport import BaseReport as HTMLReport # noqa: F401
9+
from pytest_html import extras # noqa: F401
10+
from pytest_html.fixtures import extras_stash_key
1011
from pytest_html.report import Report
1112
from pytest_html.report_data import ReportData
1213
from pytest_html.selfcontained_report import SelfContainedReport
1314

1415

1516
def pytest_addhooks(pluginmanager):
16-
from . import hooks
17+
from pytest_html import hooks
1718

1819
pluginmanager.add_hookspecs(hooks)
1920

@@ -108,45 +109,6 @@ def pytest_runtest_makereport(item, call):
108109
", use 'report.extras' instead.",
109110
DeprecationWarning,
110111
)
111-
fixture_extras = getattr(item.config, "extras", [])
112+
fixture_extras = item.config.stash.get(extras_stash_key, [])
112113
plugin_extras = getattr(report, "extras", [])
113114
report.extras = fixture_extras + plugin_extras + deprecated_extra
114-
115-
116-
@pytest.fixture
117-
def extra(pytestconfig):
118-
"""Add details to the HTML reports.
119-
120-
.. code-block:: python
121-
122-
import pytest_html
123-
124-
125-
def test_foo(extra):
126-
extra.append(pytest_html.extras.url("https://www.example.com/"))
127-
"""
128-
warnings.warn(
129-
"The 'extra' fixture is deprecated and will be removed in a future release"
130-
", use 'extras' instead.",
131-
DeprecationWarning,
132-
)
133-
pytestconfig.extras = []
134-
yield pytestconfig.extras
135-
del pytestconfig.extras[:]
136-
137-
138-
@pytest.fixture
139-
def extras(pytestconfig):
140-
"""Add details to the HTML reports.
141-
142-
.. code-block:: python
143-
144-
import pytest_html
145-
146-
147-
def test_foo(extras):
148-
extras.append(pytest_html.extras.url("https://www.example.com/"))
149-
"""
150-
pytestconfig.extras = []
151-
yield pytestconfig.extras
152-
del pytestconfig.extras[:]

src/pytest_html/report.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
from pytest_html.basereport import BaseReport
66

7+
# This Source Code Form is subject to the terms of the Mozilla Public
8+
# License, v. 2.0. If a copy of the MPL was not distributed with this
9+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
711

812
class Report(BaseReport):
913
def __init__(self, report_path, config, report_data):

src/pytest_html/report_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
14
import warnings
25
from collections import defaultdict
36

src/pytest_html/selfcontained_report.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
14
import base64
25
import binascii
36
import warnings

src/pytest_html/table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
14
import re
25
import warnings
36

src/pytest_html/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
14
import json
25
from functools import partial
36
from typing import Any

0 commit comments

Comments
 (0)