Skip to content

Traceback handling fails on apache_beam code #10602

Open
@bfontaine

Description

@bfontaine

Hello,
When running tests that use apache_beam I must use --tb=native otherwise pytest fails when trying to pretty-print the traceback of the failure.

Minimal example: https://github.com/bfontaine/pytest-beam-bug
The pyproject.toml was generated with poetry init -n; poetry add pytest apache_beam. test_a.py contains a small failing test that uses apache_beam.

To reproduce, clone the repository, then run poetry install and poetry run pytest.

Expected: a test failure
Actual: INTERNALERROR> "…/_pytest/_code/code.py", line 751, in get_source: IndexError: list index out of range

Full output
$ poetry run pytest
================================= test session starts ==================================
platform linux -- Python 3.10.9, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/baptiste/Company/pytest_beam
collected 1 item                                                                       

test_a.py 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/main.py", line 270, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/main.py", line 324, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/main.py", line 349, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/runner.py", line 112, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/runner.py", line 131, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/runner.py", line 222, in call_and_report
INTERNALERROR>     report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/skipping.py", line 265, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/runner.py", line 366, in pytest_runtest_makereport
INTERNALERROR>     return TestReport.from_item_and_call(item, call)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/reports.py", line 349, in from_item_and_call
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/python.py", line 1823, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/nodes.py", line 484, in _repr_failure_py
INTERNALERROR>     return excinfo.getrepr(
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/_code/code.py", line 669, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/_code/code.py", line 944, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo_)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/_code/code.py", line 871, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/_code/code.py", line 822, in repr_traceback_entry
INTERNALERROR>     s = self.get_source(source, line_index, excinfo, short=short)
INTERNALERROR>   File "/home/baptiste/Company/pytest_beam/.venv/lib/python3.10/site-packages/_pytest/_code/code.py", line 751, in get_source
INTERNALERROR>     lines.append(space_prefix + source.lines[line_index].strip())
INTERNALERROR> IndexError: list index out of range

================================== 1 warning in 2.00s ==================================

output of pip list

Package            Version
------------------ ----------
apache-beam        2.43.0
attrs              22.2.0
certifi            2022.12.7
charset-normalizer 2.1.1
cloudpickle        2.2.0
crcmod             1.7
dill               0.3.1.1
docopt             0.6.2
exceptiongroup     1.0.4
fastavro           1.7.0
fasteners          0.18
grpcio             1.51.1
hdfs               2.7.0
httplib2           0.20.4
idna               3.4
iniconfig          1.1.1
numpy              1.22.4
objsize            0.5.2
orjson             3.8.3
packaging          22.0
pip                22.2.2
pluggy             1.0.0
proto-plus         1.22.1
protobuf           3.19.4
pyarrow            9.0.0
pydot              1.4.2
pymongo            3.13.0
pyparsing          3.0.9
pytest             7.2.0
python-dateutil    2.8.2
pytz               2022.7
regex              2022.10.31
requests           2.28.1
setuptools         65.3.0
six                1.16.0
tomli              2.0.1
typing_extensions  4.4.0
urllib3            1.26.13
wheel              0.37.1
zstandard          0.19.0

[notice] A new release of pip available: 22.2.2 -> 22.3.1
[notice] To update, run: pip install --upgrade pip
  • Pytest version: 7.2.0
  • OS: Ubuntu 20.04.1 LTS

If I edit Pytest’s code to add print(source.lines, line_index) just above the line that fails, I get an output that ends with:

['???'] 0
['???'] 0
['???'] 0
['???'] 0
[] -1878

This explains why there is an IndexError. I’m not sure how line_index can be -1878 though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions