Fix: Use absolute path for the report (#735)
* Fix: Use absolute path for the report Fixes #732
This commit is contained in:
parent
ee21115b23
commit
82d08c46c6
|
@ -6,6 +6,13 @@ Versions follow `Semantic Versioning`_ (``<major>.<minor>.<patch>``).
|
||||||
Version History
|
Version History
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
4.0.2 (2023-09-12)
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Use absolute path to the report file.
|
||||||
|
|
||||||
|
* Thanks to `@adrien-berchet <https://github.com/adrien-berchet>`_ for reporting and for the PR.
|
||||||
|
|
||||||
4.0.1 (2023-09-10)
|
4.0.1 (2023-09-10)
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@ from pytest_html.util import cleanup_unserializable
|
||||||
|
|
||||||
class BaseReport:
|
class BaseReport:
|
||||||
def __init__(self, report_path, config, report_data, template, css):
|
def __init__(self, report_path, config, report_data, template, css):
|
||||||
self._report_path = Path(os.path.expandvars(report_path)).expanduser()
|
self._report_path = (
|
||||||
|
Path.cwd() / Path(os.path.expandvars(report_path)).expanduser()
|
||||||
|
)
|
||||||
self._report_path.parent.mkdir(parents=True, exist_ok=True)
|
self._report_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
self._config = config
|
self._config = config
|
||||||
self._template = template
|
self._template = template
|
||||||
|
@ -186,7 +188,7 @@ class BaseReport:
|
||||||
def pytest_terminal_summary(self, terminalreporter):
|
def pytest_terminal_summary(self, terminalreporter):
|
||||||
terminalreporter.write_sep(
|
terminalreporter.write_sep(
|
||||||
"-",
|
"-",
|
||||||
f"Generated html report: file://{self._report_path.resolve().as_posix()}",
|
f"Generated html report: {self._report_path.as_uri()}",
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.hookimpl(trylast=True)
|
@pytest.hookimpl(trylast=True)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -70,6 +71,27 @@ def test_html_results_summary_hook(pytester):
|
||||||
result.assert_outcomes(passed=1)
|
result.assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_chdir(pytester):
|
||||||
|
pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def changing_dir(tmp_path, monkeypatch):
|
||||||
|
monkeypatch.chdir(tmp_path)
|
||||||
|
|
||||||
|
def test_function(changing_dir):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
report_path = Path("reports") / "report.html"
|
||||||
|
page = pytester.runpytest("--html", str(report_path))
|
||||||
|
assert page.ret == 0
|
||||||
|
assert (
|
||||||
|
f"Generated html report: {(pytester.path / report_path).as_uri()}"
|
||||||
|
) in page.outlines[-2]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def css_file_path(pytester):
|
def css_file_path(pytester):
|
||||||
css_one = """
|
css_one = """
|
||||||
|
|
Loading…
Reference in New Issue