Skip to content

Feature: Add 'session' to results summary hook #660

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 1 commit into from
May 3, 2023
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
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
with:
python-version: '3.10'

- name: Ensure latest pip
run: python -m pip install --upgrade pip

- name: Install tox
run: python -m pip install --upgrade tox

Expand Down Expand Up @@ -128,9 +131,20 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Ensure latest pip
run: python -m pip install --upgrade pip

- name: Install tox
run: python -m pip install --upgrade tox

- name: Cache tox virtual environment
uses: actions/cache@v3
with:
path: .tox
key: ${{ matrix.os }}-tox-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'tox.ini') }}
restore-keys: |
${{ matrix.os }}-tox-${{ matrix.python-version }}-

- name: Run unit tests
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
run: tox -e py${{ matrix.python-version }}-cov -- testing/test_unit.py
Expand Down Expand Up @@ -196,9 +210,20 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Ensure latest pip
run: python -m pip install --upgrade pip

- name: Install tox
run: python -m pip install --upgrade tox

- name: Cache tox virtual environment
uses: actions/cache@v3
with:
path: .tox
key: ubuntu-latest-tox-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'tox.ini') }}
restore-keys: |
ubuntu-latest-tox-${{ matrix.python-version }}-

- name: Run integration tests
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
run: tox -e ${{ matrix.python-version }}-cov -- testing/test_integration.py
Expand Down
1 change: 1 addition & 0 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def pytest_sessionfinish(self, session):
prefix=self._report.data["additionalSummary"]["prefix"],
summary=self._report.data["additionalSummary"]["summary"],
postfix=self._report.data["additionalSummary"]["postfix"],
session=session,
)
self._report.set_data("runningState", "Finished")
self._generate_report()
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_html/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def pytest_html_report_title(report):
"""Called before adding the title to the report"""


def pytest_html_results_summary(prefix, summary, postfix):
def pytest_html_results_summary(prefix, summary, postfix, session):
"""Called before adding the summary section to the report"""


Expand Down
11 changes: 4 additions & 7 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from base64 import b64encode
from pathlib import Path

import pkg_resources
import pytest
from assertpy import assert_that
from bs4 import BeautifulSoup
Expand All @@ -28,12 +27,8 @@


def run(pytester, path="report.html", cmd_flags=None, query_params=None):
if cmd_flags is None:
cmd_flags = []

if query_params is None:
query_params = {}
query_params = urllib.parse.urlencode(query_params)
cmd_flags = cmd_flags or []
query_params = urllib.parse.urlencode(query_params) if query_params else {}

path = pytester.path.joinpath(path)
pytester.runpytest("--html", path, *cmd_flags)
Expand Down Expand Up @@ -120,6 +115,8 @@ def file_content():
)
except AttributeError:
# Needed for python < 3.9
import pkg_resources

return pkg_resources.resource_string(
"pytest_html", os.path.join("resources", "style.css")
).decode("utf-8")
Expand Down
24 changes: 22 additions & 2 deletions testing/test_unit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pytest_plugins = ("pytester",)


def run(pytester, path="report.html", *args):
def run(pytester, path="report.html", cmd_flags=None):
cmd_flags = cmd_flags or []
path = pytester.path.joinpath(path)
return pytester.runpytest("--html", path, *args)
return pytester.runpytest("--html", path, *cmd_flags)


def test_duration_format_deprecation_warning(pytester):
Expand All @@ -19,8 +20,27 @@ def pytest_runtest_makereport(item, call):
)
pytester.makepyfile("def test_pass(): pass")
result = run(pytester)
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(
[
"*DeprecationWarning: 'duration_formatter'*",
],
)


def test_html_results_summary_hook(pytester):
pytester.makeconftest(
"""
import pytest

def pytest_html_results_summary(prefix, summary, postfix, session):
print(prefix)
print(summary)
print(postfix)
print(session)
"""
)

pytester.makepyfile("def test_pass(): pass")
result = run(pytester)
result.assert_outcomes(passed=1)