1
+ from _pytest .pathlib import Path
1
2
from _pytest .reports import CollectReport
2
3
from _pytest .reports import TestReport
3
4
@@ -11,7 +12,6 @@ def test_xdist_longrepr_to_str_issue_241(self, testdir):
11
12
"""
12
13
testdir .makepyfile (
13
14
"""
14
- import os
15
15
def test_a(): assert False
16
16
def test_b(): pass
17
17
"""
@@ -35,8 +35,8 @@ def test_xdist_report_longrepr_reprcrash_130(self, testdir):
35
35
"""
36
36
reprec = testdir .inline_runsource (
37
37
"""
38
- import py
39
- def test_fail(): assert False, 'Expected Message'
38
+ def test_fail():
39
+ assert False, 'Expected Message'
40
40
"""
41
41
)
42
42
reports = reprec .getreports ("pytest_runtest_logreport" )
@@ -201,6 +201,24 @@ def test_extended_report_deserialization(self, testdir):
201
201
if rep .failed :
202
202
assert newrep .longrepr == str (rep .longrepr )
203
203
204
+ def test_paths_support (self , testdir ):
205
+ """Report attributes which are py.path or pathlib objects should become strings."""
206
+ testdir .makepyfile (
207
+ """
208
+ def test_a():
209
+ assert False
210
+ """
211
+ )
212
+ reprec = testdir .inline_run ()
213
+ reports = reprec .getreports ("pytest_runtest_logreport" )
214
+ assert len (reports ) == 3
215
+ test_a_call = reports [1 ]
216
+ test_a_call .path1 = testdir .tmpdir
217
+ test_a_call .path2 = Path (testdir .tmpdir )
218
+ data = test_a_call ._to_json ()
219
+ assert data ["path1" ] == str (testdir .tmpdir )
220
+ assert data ["path2" ] == str (testdir .tmpdir )
221
+
204
222
205
223
class TestHooks :
206
224
"""Test that the hooks are working correctly for plugins"""
0 commit comments