diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c41b6d38..9f9d7b47 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -78,7 +78,8 @@ jobs: }} uses: codecov/codecov-action@v3 with: - fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false files: ./cobertura-coverage.xml flags: js_tests name: ubuntu-latest-node-16 @@ -163,7 +164,8 @@ jobs: }} uses: codecov/codecov-action@v3 with: - fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false files: ./coverage.xml flags: py_unit_tests name: ${{ matrix.os }}-python-${{ matrix.python-version }} @@ -236,7 +238,8 @@ jobs: }} uses: codecov/codecov-action@v3 with: - fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false files: ./coverage.xml flags: py_integration_tests name: ubuntu-latest-${{ matrix.python-version }} diff --git a/pyproject.toml b/pyproject.toml index 18b99087..3e45bf4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ Source = "https://github.com/pytest-dev/pytest-html" [project.entry-points.pytest11] html = "pytest_html.plugin" +html_fixtures = "pytest_html.fixtures" [tool.hatch.envs.test] features = [ diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index 89817d1b..8caa66bb 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -1,3 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. import datetime import json import os diff --git a/src/pytest_html/fixtures.py b/src/pytest_html/fixtures.py new file mode 100644 index 00000000..88ce828d --- /dev/null +++ b/src/pytest_html/fixtures.py @@ -0,0 +1,47 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +import warnings + +import pytest + +extras_stash_key = pytest.StashKey[list]() + + +@pytest.fixture +def extra(pytestconfig): + """DEPRECATED: Add details to the HTML reports. + + .. code-block:: python + + import pytest_html + + + def test_foo(extra): + extra.append(pytest_html.extras.url("https://www.example.com/")) + """ + warnings.warn( + "The 'extra' fixture is deprecated and will be removed in a future release" + ", use 'extras' instead.", + DeprecationWarning, + ) + pytestconfig.stash[extras_stash_key] = [] + yield pytestconfig.stash[extras_stash_key] + del pytestconfig.stash[extras_stash_key][:] + + +@pytest.fixture +def extras(pytestconfig): + """Add details to the HTML reports. + + .. code-block:: python + + import pytest_html + + + def test_foo(extras): + extras.append(pytest_html.extras.url("https://www.example.com/")) + """ + pytestconfig.stash[extras_stash_key] = [] + yield pytestconfig.stash[extras_stash_key] + del pytestconfig.stash[extras_stash_key][:] diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index fd43055b..6683c54a 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -6,14 +6,15 @@ import pytest -from pytest_html.basereport import BaseReport as HTMLReport # noqa: F401 +from pytest_html import extras # noqa: F401 +from pytest_html.fixtures import extras_stash_key from pytest_html.report import Report from pytest_html.report_data import ReportData from pytest_html.selfcontained_report import SelfContainedReport def pytest_addhooks(pluginmanager): - from . import hooks + from pytest_html import hooks pluginmanager.add_hookspecs(hooks) @@ -108,45 +109,6 @@ def pytest_runtest_makereport(item, call): ", use 'report.extras' instead.", DeprecationWarning, ) - fixture_extras = getattr(item.config, "extras", []) + fixture_extras = item.config.stash.get(extras_stash_key, []) plugin_extras = getattr(report, "extras", []) report.extras = fixture_extras + plugin_extras + deprecated_extra - - -@pytest.fixture -def extra(pytestconfig): - """Add details to the HTML reports. - - .. code-block:: python - - import pytest_html - - - def test_foo(extra): - extra.append(pytest_html.extras.url("https://www.example.com/")) - """ - warnings.warn( - "The 'extra' fixture is deprecated and will be removed in a future release" - ", use 'extras' instead.", - DeprecationWarning, - ) - pytestconfig.extras = [] - yield pytestconfig.extras - del pytestconfig.extras[:] - - -@pytest.fixture -def extras(pytestconfig): - """Add details to the HTML reports. - - .. code-block:: python - - import pytest_html - - - def test_foo(extras): - extras.append(pytest_html.extras.url("https://www.example.com/")) - """ - pytestconfig.extras = [] - yield pytestconfig.extras - del pytestconfig.extras[:] diff --git a/src/pytest_html/report.py b/src/pytest_html/report.py index ed1cd9ed..0ef36f6c 100644 --- a/src/pytest_html/report.py +++ b/src/pytest_html/report.py @@ -4,6 +4,10 @@ from pytest_html.basereport import BaseReport +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + class Report(BaseReport): def __init__(self, report_path, config, report_data): diff --git a/src/pytest_html/report_data.py b/src/pytest_html/report_data.py index 1a966ed5..a9889c12 100644 --- a/src/pytest_html/report_data.py +++ b/src/pytest_html/report_data.py @@ -1,3 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. import warnings from collections import defaultdict diff --git a/src/pytest_html/selfcontained_report.py b/src/pytest_html/selfcontained_report.py index c5fd1e6b..dc48d59f 100644 --- a/src/pytest_html/selfcontained_report.py +++ b/src/pytest_html/selfcontained_report.py @@ -1,3 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. import base64 import binascii import warnings diff --git a/src/pytest_html/table.py b/src/pytest_html/table.py index 7fc6e3a0..54aafa9e 100644 --- a/src/pytest_html/table.py +++ b/src/pytest_html/table.py @@ -1,3 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. import re import warnings diff --git a/src/pytest_html/util.py b/src/pytest_html/util.py index 3d1dea0e..a40bdd30 100644 --- a/src/pytest_html/util.py +++ b/src/pytest_html/util.py @@ -1,3 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. import json from functools import partial from typing import Any