MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_paths_support

Method test_paths_support

testing/test_reports.py:226–250  ·  view source on GitHub ↗

Report attributes which are path-like should become strings.

(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

224 assert newrep.longrepr == str(rep.longrepr)
225
226 def test_paths_support(self, pytester: Pytester) -> None:
227 """Report attributes which are path-like should become strings."""
228 pytester.makepyfile(
229 """
230 def test_a():
231 assert False
232 """
233 )
234
235 class MyPathLike:
236 def __init__(self, path: str) -> None:
237 self.path = path
238
239 def __fspath__(self) -> str:
240 return self.path
241
242 reprec = pytester.inline_run()
243 reports = reprec.getreports("pytest_runtest_logreport")
244 assert len(reports) == 3
245 test_a_call = reports[1]
246 test_a_call.path1 = MyPathLike(str(pytester.path)) # type: ignore[attr-defined]
247 test_a_call.path2 = pytester.path # type: ignore[attr-defined]
248 data = test_a_call._to_json()
249 assert data["path1"] == str(pytester.path)
250 assert data["path2"] == str(pytester.path)
251
252 def test_deserialization_failure(self, pytester: Pytester) -> None:
253 """Check handling of failure during deserialization of report types."""

Callers

nothing calls this directly

Calls 5

MyPathLikeClass · 0.85
_to_jsonMethod · 0.80
makepyfileMethod · 0.45
inline_runMethod · 0.45
getreportsMethod · 0.45

Tested by

no test coverage detected