Skip to content

Commit 82d08c4

Browse files
Fix: Use absolute path for the report (#735)
* Fix: Use absolute path for the report Fixes #732
1 parent ee21115 commit 82d08c4

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

docs/changelog.rst

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Versions follow `Semantic Versioning`_ (``<major>.<minor>.<patch>``).
66
Version History
77
---------------
88

9+
4.0.2 (2023-09-12)
10+
~~~~~~~~~~~~~~~~~~
11+
12+
* Use absolute path to the report file.
13+
14+
* Thanks to `@adrien-berchet <https://github.com/adrien-berchet>`_ for reporting and for the PR.
15+
916
4.0.1 (2023-09-10)
1017
~~~~~~~~~~~~~~~~~~
1118

src/pytest_html/basereport.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
class BaseReport:
2020
def __init__(self, report_path, config, report_data, template, css):
21-
self._report_path = Path(os.path.expandvars(report_path)).expanduser()
21+
self._report_path = (
22+
Path.cwd() / Path(os.path.expandvars(report_path)).expanduser()
23+
)
2224
self._report_path.parent.mkdir(parents=True, exist_ok=True)
2325
self._config = config
2426
self._template = template
@@ -186,7 +188,7 @@ def pytest_sessionfinish(self, session):
186188
def pytest_terminal_summary(self, terminalreporter):
187189
terminalreporter.write_sep(
188190
"-",
189-
f"Generated html report: file://{self._report_path.resolve().as_posix()}",
191+
f"Generated html report: {self._report_path.as_uri()}",
190192
)
191193

192194
@pytest.hookimpl(trylast=True)

testing/test_unit.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import importlib.resources
22
import os
33
import sys
4+
from pathlib import Path
45

56
import pkg_resources
67
import pytest
@@ -70,6 +71,27 @@ def pytest_html_results_summary(prefix, summary, postfix, session):
7071
result.assert_outcomes(passed=1)
7172

7273

74+
def test_chdir(pytester):
75+
pytester.makepyfile(
76+
"""
77+
import pytest
78+
79+
@pytest.fixture
80+
def changing_dir(tmp_path, monkeypatch):
81+
monkeypatch.chdir(tmp_path)
82+
83+
def test_function(changing_dir):
84+
pass
85+
"""
86+
)
87+
report_path = Path("reports") / "report.html"
88+
page = pytester.runpytest("--html", str(report_path))
89+
assert page.ret == 0
90+
assert (
91+
f"Generated html report: {(pytester.path / report_path).as_uri()}"
92+
) in page.outlines[-2]
93+
94+
7395
@pytest.fixture
7496
def css_file_path(pytester):
7597
css_one = """

0 commit comments

Comments
 (0)