diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 71e508f8..e17374fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index 8caa66bb..969a0fee 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -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() diff --git a/src/pytest_html/hooks.py b/src/pytest_html/hooks.py index f81f9e25..1d1b269d 100644 --- a/src/pytest_html/hooks.py +++ b/src/pytest_html/hooks.py @@ -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""" diff --git a/testing/test_integration.py b/testing/test_integration.py index a562e275..5b8bce12 100644 --- a/testing/test_integration.py +++ b/testing/test_integration.py @@ -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 @@ -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) @@ -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") diff --git a/testing/test_unit.py b/testing/test_unit.py index 18ed204a..f60132e4 100644 --- a/testing/test_unit.py +++ b/testing/test_unit.py @@ -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 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)