Use concurrent.futures for fidelity to the original report

As requested in review
This commit is contained in:
Bruno Oliveira 2020-01-07 12:45:18 -03:00
parent 0e00069340
commit 356d865ad7
1 changed files with 9 additions and 15 deletions

View File

@ -320,25 +320,19 @@ class TestReportSerialization:
"""Regression test for tracebacks without a reprcrash (#5971) """Regression test for tracebacks without a reprcrash (#5971)
This happens notably on exceptions raised by multiprocess.pool: the exception transfer This happens notably on exceptions raised by multiprocess.pool: the exception transfer
from subprocess to main process creates an artificial exception which, ExceptionInfo from subprocess to main process creates an artificial exception, which ExceptionInfo
can't obtain the ReprFileLocation from. can't obtain the ReprFileLocation from.
""" """
testdir.makepyfile( testdir.makepyfile(
""" """
# equivalent of multiprocessing.pool.RemoteTraceback from concurrent.futures import ProcessPoolExecutor
class RemoteTraceback(Exception):
def __init__(self, tb): def func():
self.tb = tb raise ValueError('value error')
def __str__(self):
return self.tb
def test_a(): def test_a():
try: with ProcessPoolExecutor() as p:
raise ValueError('value error') p.submit(func).result()
except ValueError as e:
# equivalent to how multiprocessing.pool.rebuild_exc does it
e.__cause__ = RemoteTraceback('runtime error')
raise e
""" """
) )
reprec = testdir.inline_run() reprec = testdir.inline_run()
@ -352,8 +346,8 @@ class TestReportSerialization:
tb1, fileloc1, desc1 = entry1 tb1, fileloc1, desc1 = entry1
tb2, fileloc2, desc2 = entry2 tb2, fileloc2, desc2 = entry2
assert "RemoteTraceback: runtime error" in str(tb1) assert "RemoteTraceback" in str(tb1)
assert "ValueError('value error')" in str(tb2) assert "ValueError: value error" in str(tb2)
assert fileloc1 is None assert fileloc1 is None
assert fileloc2.message == "ValueError: value error" assert fileloc2.message == "ValueError: value error"