Merge pull request #178 from timyhou/locals_d_issue

Unserialize reprlocals to a ReprLocal instance
This commit is contained in:
Bruno Oliveira
2017-07-05 12:46:41 -03:00
committed by GitHub
3 changed files with 53 additions and 10 deletions

1
changelog/176.bugfix Normal file
View File

@@ -0,0 +1 @@
Fix ``ReprLocal`` not being unserialized breaking --showlocals usages.

View File

@@ -86,15 +86,54 @@ class TestReportSerialization:
""") """)
reports = reprec.getreports("pytest_runtest_logreport") reports = reprec.getreports("pytest_runtest_logreport")
assert len(reports) == 3 assert len(reports) == 3
initial_failure_report = reports[1] rep = reports[1]
added_section = ('Failure Metadata', str("metadata metadata"), "*") added_section = ('Failure Metadata', str("metadata metadata"), "*")
initial_failure_report.longrepr.sections.append(added_section) rep.longrepr.sections.append(added_section)
d = serialize_report(initial_failure_report) d = serialize_report(rep)
check_marshallable(d) check_marshallable(d)
processed_report = unserialize_report("testreport", d) a = unserialize_report("testreport", d)
assert 'Expected Message' \ # Check assembled == rep
in processed_report.longrepr.reprcrash.message assert a.__dict__.keys() == rep.__dict__.keys()
assert added_section in processed_report.longrepr.sections for key in rep.__dict__.keys():
if key != 'longrepr':
assert getattr(a, key) == getattr(rep, key)
assert rep.longrepr.reprcrash.lineno == a.longrepr.reprcrash.lineno
assert rep.longrepr.reprcrash.message == a.longrepr.reprcrash.message
assert rep.longrepr.reprcrash.path == a.longrepr.reprcrash.path
assert rep.longrepr.reprtraceback.entrysep \
== a.longrepr.reprtraceback.entrysep
assert rep.longrepr.reprtraceback.extraline \
== a.longrepr.reprtraceback.extraline
assert rep.longrepr.reprtraceback.style \
== a.longrepr.reprtraceback.style
assert rep.longrepr.sections == a.longrepr.sections
assert rep.longrepr.reprtraceback.reprentries \
== a.longrepr.reprtraceback.reprentries
# Missing section attribute PR171
assert added_section in a.longrepr.sections
def test_reprentries_serialization_170(self, testdir):
reprec = testdir.inline_runsource("""
def test_fail():
x = 0
assert x
""", '--showlocals', '-n1')
reports = reprec.getreports("pytest_runtest_logreport")
assert len(reports) == 3
rep = reports[1]
d = serialize_report(rep)
a = unserialize_report("testreport", d)
rep_entries = rep.longrepr.reprtraceback.reprentries
a_entries = a.longrepr.reprtraceback.reprentries
assert rep_entries == a_entries
for i in range(len(a_entries)):
assert rep_entries[i].lines == a_entries[i].lines
assert rep_entries[i].localssep == a_entries[i].localssep
assert rep_entries[i].reprfileloc == a_entries[i].reprfileloc
assert rep_entries[i].reprfuncargs == a_entries[i].reprfuncargs
assert rep_entries[i].reprlocals == a_entries[i].reprlocals
assert rep_entries[i].style == a_entries[i].style
def test_itemreport_outcomes(self, testdir): def test_itemreport_outcomes(self, testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""

View File

@@ -329,10 +329,11 @@ class SlaveController(object):
def unserialize_report(name, reportdict): def unserialize_report(name, reportdict):
def assembled_report(reportdict): def assembled_report(reportdict):
from _pytest._code.code import ( from _pytest._code.code import (
ReprEntry,
ReprExceptionInfo, ReprExceptionInfo,
ReprFileLocation, ReprFileLocation,
ReprEntry,
ReprFuncArgs, ReprFuncArgs,
ReprLocals,
ReprTraceback ReprTraceback
) )
if reportdict['longrepr']: if reportdict['longrepr']:
@@ -343,16 +344,18 @@ def unserialize_report(name, reportdict):
unserialized_entries = [] unserialized_entries = []
for entry in reprtraceback['reprentries']: for entry in reprtraceback['reprentries']:
reprfuncargs, reprfileloc = None, None reprfuncargs, reprfileloc, reprlocals = None, None, None
if entry['reprfuncargs']: if entry['reprfuncargs']:
reprfuncargs = ReprFuncArgs(**entry['reprfuncargs']) reprfuncargs = ReprFuncArgs(**entry['reprfuncargs'])
if entry['reprfileloc']: if entry['reprfileloc']:
reprfileloc = ReprFileLocation(**entry['reprfileloc']) reprfileloc = ReprFileLocation(**entry['reprfileloc'])
if entry['reprlocals']:
reprlocals = ReprLocals(entry['reprlocals']['lines'])
reprentry = ReprEntry( reprentry = ReprEntry(
lines=entry['lines'], lines=entry['lines'],
reprfuncargs=reprfuncargs, reprfuncargs=reprfuncargs,
reprlocals=entry['reprlocals'], reprlocals=reprlocals,
filelocrepr=reprfileloc, filelocrepr=reprfileloc,
style=entry['style'] style=entry['style']
) )