pytest-dev / pytest-dev/pytest-bdd
INTERNALERROR> IndexError: list index out of range
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 251
- Avg merge
- 43m
- Merged PRs (30d)
- 2
Description
I'm not sure if this is a pytest-bdd or a pytest core bug - but I've not seen it outside of pytest-bdd, so I'm reporting it here. Please let me know if I'm wrong! 😄
I found various ways to trigger this exception - for example when using an undefined fixture in a bdd test.
feat.feature:
Feature: feat
Scenario: scen
Given foo
When bar
Then baz
test_foo.py:
import pytest_bdd as bdd
@bdd.given('foo')
def foo(blah): # using blah fixture which doesn't exist
pass
@bdd.when('bar')
def bar():
pass
@bdd.then('baz')
def baz():
pass
bdd.scenarios('feat.feature')
gives me:
platform linux -- Python 3.5.0, pytest-2.8.2.dev1, py-1.4.30, pluggy-0.3.1
rootdir: /home/florian/tmp/bdd, inifile:
plugins: bdd-2.15.0, mock-0.8.1
collected 1 items
test_foo.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/main.py", line 121, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR> return call_outcome.get_result()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/runner.py", line 75, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR> report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR> return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR> wrap_controller.send(call_outcome)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR> rep = outcome.get_result()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 278, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR> self.result = func()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/florian/.venv/lib/python3.5/site-packages/pytest_bdd/reporting.py", line 150, in pytest_runtest_makereport
INTERNALERROR> rep = __multicall__.execute()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/runner.py", line 224, in pytest_runtest_makereport
INTERNALERROR> longrepr = item.repr_failure(excinfo)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/python.py", line 725, in repr_failure
INTERNALERROR> return self._repr_failure_py(excinfo, style=style)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/python.py", line 718, in _repr_failure_py
INTERNALERROR> style=style)
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/main.py", line 392, in _repr_failure_py
INTERNALERROR> return excinfo.value.formatrepr()
INTERNALERROR> File "/usr/lib/python3.5/site-packages/_pytest/python.py", line 1720, in formatrepr
INTERNALERROR> lines, _ = inspect.getsourcelines(get_real_func(function))
INTERNALERROR> File "/usr/lib64/python3.5/inspect.py", line 930, in getsourcelines
INTERNALERROR> lines, lnum = findsource(object)
INTERNALERROR> File "/usr/lib64/python3.5/inspect.py", line 803, in findsource
INTERNALERROR> if pat.match(lines[lnum]): break
INTERNALERROR> IndexError: list index out of range
I also see this with Python 3.4 and pytest 2.7.
I can also reproduce it by decorating a fixture with @bdd.given and @bdd.when - same feature file as above, with this test_foo.py:
import pytest_bdd as bdd
@bdd.given('foo')
@bdd.when('bar')
def foobar():
pass
@bdd.then('baz')
def baz():
pass
bdd.scenarios('feat.feature')
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the undefined-fixture and doubly decorated-step examples, then inspect pytest_bdd/reporting.py around line 150 and the traceback path through pytest's failure representation. Done means these cases report their underlying test errors without raising the IndexError INTERNALERROR.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100