Improve coverage for to_json() with paths in reports
This commit is contained in:
parent
e4eec3416a
commit
ceef0af1ae
|
@ -11,6 +11,7 @@ from _pytest._code.code import ReprLocals
|
||||||
from _pytest._code.code import ReprTraceback
|
from _pytest._code.code import ReprTraceback
|
||||||
from _pytest._code.code import TerminalRepr
|
from _pytest._code.code import TerminalRepr
|
||||||
from _pytest.outcomes import skip
|
from _pytest.outcomes import skip
|
||||||
|
from _pytest.pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def getslaveinfoline(node):
|
def getslaveinfoline(node):
|
||||||
|
@ -189,7 +190,7 @@ class BaseReport(object):
|
||||||
else:
|
else:
|
||||||
d["longrepr"] = self.longrepr
|
d["longrepr"] = self.longrepr
|
||||||
for name in d:
|
for name in d:
|
||||||
if isinstance(d[name], py.path.local):
|
if isinstance(d[name], (py.path.local, Path)):
|
||||||
d[name] = str(d[name])
|
d[name] = str(d[name])
|
||||||
elif name == "result":
|
elif name == "result":
|
||||||
d[name] = None # for now
|
d[name] = None # for now
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from _pytest.pathlib import Path
|
||||||
from _pytest.reports import CollectReport
|
from _pytest.reports import CollectReport
|
||||||
from _pytest.reports import TestReport
|
from _pytest.reports import TestReport
|
||||||
|
|
||||||
|
@ -11,7 +12,6 @@ class TestReportSerialization(object):
|
||||||
"""
|
"""
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
def test_a(): assert False
|
def test_a(): assert False
|
||||||
def test_b(): pass
|
def test_b(): pass
|
||||||
"""
|
"""
|
||||||
|
@ -35,8 +35,8 @@ class TestReportSerialization(object):
|
||||||
"""
|
"""
|
||||||
reprec = testdir.inline_runsource(
|
reprec = testdir.inline_runsource(
|
||||||
"""
|
"""
|
||||||
import py
|
def test_fail():
|
||||||
def test_fail(): assert False, 'Expected Message'
|
assert False, 'Expected Message'
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reports = reprec.getreports("pytest_runtest_logreport")
|
reports = reprec.getreports("pytest_runtest_logreport")
|
||||||
|
@ -201,6 +201,24 @@ class TestReportSerialization(object):
|
||||||
if rep.failed:
|
if rep.failed:
|
||||||
assert newrep.longrepr == str(rep.longrepr)
|
assert newrep.longrepr == str(rep.longrepr)
|
||||||
|
|
||||||
|
def test_paths_support(self, testdir):
|
||||||
|
"""Report attributes which are py.path or pathlib objects should become strings."""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_a():
|
||||||
|
assert False
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
reprec = testdir.inline_run()
|
||||||
|
reports = reprec.getreports("pytest_runtest_logreport")
|
||||||
|
assert len(reports) == 3
|
||||||
|
test_a_call = reports[1]
|
||||||
|
test_a_call.path1 = testdir.tmpdir
|
||||||
|
test_a_call.path2 = Path(testdir.tmpdir)
|
||||||
|
data = test_a_call._to_json()
|
||||||
|
assert data["path1"] == str(testdir.tmpdir)
|
||||||
|
assert data["path2"] == str(testdir.tmpdir)
|
||||||
|
|
||||||
|
|
||||||
class TestHooks:
|
class TestHooks:
|
||||||
"""Test that the hooks are working correctly for plugins"""
|
"""Test that the hooks are working correctly for plugins"""
|
||||||
|
|
Loading…
Reference in New Issue