Skip to content

Chore: Assorted fixes around pytest entry points #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 47 additions & 0 deletions src/pytest_html/fixtures.py
Original file line number Diff line number Diff line change
@@ -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][:]
46 changes: 4 additions & 42 deletions src/pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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[:]
4 changes: 4 additions & 0 deletions src/pytest_html/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_html/report_data.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/pytest_html/selfcontained_report.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_html/table.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/pytest_html/util.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down