Feature: Add 'session' to results summary hook (#660)
This commit is contained in:
parent
48e20c19d1
commit
50dfbe7894
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -173,6 +173,7 @@ class BaseReport:
|
|||
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()
|
||||
|
|
|
@ -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"""
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import urllib.parse
|
|||
from base64 import b64encode
|
||||
from pathlib import Path
|
||||
|
||||
import pkg_resources
|
||||
import pytest
|
||||
from assertpy import assert_that
|
||||
from bs4 import BeautifulSoup
|
||||
|
@ -28,12 +27,8 @@ OUTCOMES = {
|
|||
|
||||
|
||||
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)
|
||||
|
@ -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")
|
||||
|
|
|
@ -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):
|
||||
|
@ -19,8 +20,27 @@ def test_duration_format_deprecation_warning(pytester):
|
|||
)
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue