Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNALERROR> IndexError: list index out of range (Python 3.4) #752

Closed
pytestbot opened this issue May 23, 2015 · 11 comments
Closed

INTERNALERROR> IndexError: list index out of range (Python 3.4) #752

pytestbot opened this issue May 23, 2015 · 11 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Andrew Gorcester (BitBucket: andrewsg, GitHub: andrewsg)


After changing a line of source inside a dict literal in my project from this:

#!python

    0x0b: (self.ANC, "IMM"),

to this:

#!python

    0x0b: None, #(self.ANC, "IMM"),

py.test started throwing the following error:

#!

platform linux -- Python 3.4.0 -- py-1.4.27 -- pytest-2.7.1
rootdir: /home/andrewsg/src/python-c64, inifile: 
collected 108 items 

test_c64.py .......
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/main.py", line 84, in wrap_session
INTERNALERROR>     doit(config, session)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/main.py", line 122, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/main.py", line 142, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR>     return wrapped_call(method(*args), self.execute)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 113, in wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 137, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/runner.py", line 75, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR>     return wrapped_call(method(*args), self.execute)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 109, in wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/skipping.py", line 157, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 137, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/runner.py", line 224, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/python.py", line 625, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/python.py", line 618, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/_pytest/main.py", line 410, in _repr_failure_py
INTERNALERROR>     style=style, tbfilter=tbfilter)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/py/_code/code.py", line 412, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/py/_code/code.py", line 582, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/py/_code/code.py", line 543, in repr_traceback_entry
INTERNALERROR>     s = self.get_source(source, line_index, excinfo, short=short)
INTERNALERROR>   File "/home/andrewsg/src/py34env/lib/python3.4/site-packages/py/_code/code.py", line 484, in get_source
INTERNALERROR>     lines.append(self.flow_marker + "   " + source.lines[line_index])
INTERNALERROR> IndexError: list index out of range

=========================== 7 passed in 0.06 seconds ===========================

I saw #560 with the same error message, but it looks like this is a different issue; at the least, my version is much newer than the patch date for that issue's resolution.


@pytestbot
Copy link
Contributor Author

Original comment by Andrew Gorcester (BitBucket: andrewsg, GitHub: andrewsg):


The project is available online, pinned to the offending commit: https://github.com/andrewsg/python-c64/tree/ed738342c1e3f30b19db5b1c878c8c4547435c0d

The problematic line is c64.py line 172. Lines prior to that, even though they may follow the exact same pattern, do not cause an error.

@pytestbot
Copy link
Contributor Author

Original comment by Anthon van der Neut (BitBucket: anthon_van_der_neut, GitHub: anthon_van_der_neut):


I can confirm this error with this minimal fail.py file:

def round_trip(dinp):
     assert 1 == dinp


def test_rt():
     round_trip("""
""")

Fails on 2.7.10, 2.6, 3.3 and 3.4. Inserting 4 spaces before the closing """ removes the error in this case ( I found this with a more complex example, where changing the string that way does not help but this example is the result of minimizing the fail case).

@pytestbot
Copy link
Contributor Author

Original comment by Daniel Hahler (BitBucket: blueyed, GitHub: blueyed):


Here is another case:

The code, where the commented "password" line seems to cause the offset error:

@pytest.fixture
def staff_user(db):
    "A fixture to provide a staff user."
    from django_factory_boy import auth as auth_factories
    user = auth_factories.UserFactory(
        username='staff-test-user',
        # password="123456",
        is_staff=True)
    # group = Group.objects.get('Staff')
    # user.groups.add(group)
    return user


ipdb> p source.lines
['@pytest.fixture', 'def staff_user(db):', '    "A fixture to provide a staff user."', '    from django_factory_boy import auth as auth_factories', '    user = auth_factories.UserFactory(', "        username='staff-test-user',"]

ipdb> p line_index
7

ipdb> p len(source.lines)
6

@pytestbot
Copy link
Contributor Author

Original comment by Daniel Hahler (BitBucket: blueyed, GitHub: blueyed):


There are several duplicates / similar issues about this: https://bitbucket.org/pytest-dev/pytest/issues?status=new&status=open&q=list%20index%20out%20of%20range

@pytestbot
Copy link
Contributor Author

Original comment by Daniel Hahler (BitBucket: blueyed, GitHub: blueyed):


Bisecting pylib shows up this as first bad commit:

The first bad revision is:
changeset:   2268:d7d5337ac74a
branch:      astcomments
user:        Thomas Tanner <X>
date:        Sat Dec 27 01:47:36 2014 +0100
summary:     source:getstatementrange_ast: search the code block end from the beginning, not from the end

https://bitbucket.org/pytest-dev/py/commits/d7d5337ac74a054ad13bc7e28f976d00f051ace3

@pytestbot
Copy link
Contributor Author

Original comment by Daniel Hahler (BitBucket: blueyed, GitHub: blueyed):


The issue in pylib is the following: https://bitbucket.org/pytest-dev/py/issue/55/broken-comment-parsing

@srkunze
Copy link

srkunze commented Jun 16, 2015

Is there already a solution for this issue?

@keleshev
Copy link

I'm getting a similar error message. Here's how I can reproduce it:

$ cat test_pytest.py
def test_pytest():
    foo = {
        #
        'bar': 1 / 0
    }
$ py.test test_pytest.py

========================================================================== test session starts ===========================================================================
platform darwin -- Python 2.7.8 -- py-1.4.27 -- pytest-2.7.0
rootdir: /Users/vladimir/Developer, inifile:
collected 1 items

test_pytest.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/main.py", line 84, in wrap_session
INTERNALERROR>     doit(config, session)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/main.py", line 122, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/main.py", line 142, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR>     return wrapped_call(method(*args), self.execute)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 113, in wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 138, in get_result
INTERNALERROR>     py.builtin._reraise(*ex)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/runner.py", line 75, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR>     return wrapped_call(method(*args), self.execute)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 109, in wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/skipping.py", line 157, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 138, in get_result
INTERNALERROR>     py.builtin._reraise(*ex)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/runner.py", line 224, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/python.py", line 625, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/python.py", line 618, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/_pytest/main.py", line 410, in _repr_failure_py
INTERNALERROR>     style=style, tbfilter=tbfilter)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/py/_code/code.py", line 412, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/py/_code/code.py", line 582, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/py/_code/code.py", line 543, in repr_traceback_entry
INTERNALERROR>     s = self.get_source(source, line_index, excinfo, short=short)
INTERNALERROR>   File "/usr/local/lib/python2.7/site-packages/py/_code/code.py", line 484, in get_source
INTERNALERROR>     lines.append(self.flow_marker + "   " + source.lines[line_index])
INTERNALERROR> IndexError: list index out of range

============================================================================  in 0.01 seconds ============================================================================

@keleshev
Copy link

An even smaller example that reproduces it:

$ cat test_pytest.py
(
    #
    1 / 0
)

Removing the comment fixes it.

@blueyed
Copy link
Contributor

blueyed commented Jun 24, 2015

The issue in pylib (https://bitbucket.org/pytest-dev/py/issue/55/broken-comment-parsing) is fixed and has been released in py 1.4.29.

Closing this issue for pytest therefore.

@blueyed blueyed closed this as completed Jun 24, 2015
@AvdN
Copy link
Contributor

AvdN commented Nov 20, 2016

A bit delayed, but I just came across my workaround for this, in ruamel.yaml.
I removed the workarounds and can confirm this is solved.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

5 participants