Skip to content

Internal IndexError when testing #11953

Closed

Description

@solaluset

I've encountered a strange IndexError when testing my package on GitHub Actions. It doesn't happen locally and only Python 3.11+ is affected.

pytest is 8.0.0, OS is ubuntu-20.04
Here's the log from the failed action: logs.txt

You can check my repository for details: https://github.com/solaluset/pwcp/tree/rename

Activity

  1. The-Compiler commented on Feb 8, 2024

    @The-Compiler
    Member

    Relevant part of the logs:

    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/main.py", line 272, in wrap_session
        session.exitstatus = doit(config, session) or 0
                             ^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/main.py", line 326, in _main
        config.hook.pytest_runtestloop(session=session)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
        return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
        return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 138, in _multicall
        raise exception.with_traceback(exception.__traceback__)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/logging.py", line 796, in pytest_runtestloop
        return (yield)  # Run all the tests.
                ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
        res = hook_impl.function(*args)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/main.py", line 351, in pytest_runtestloop
        item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
        return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
        return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 138, in _multicall
        raise exception.with_traceback(exception.__traceback__)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/warnings.py", line 109, in pytest_runtest_protocol
        return (yield)
                ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/assertion/__init__.py", line 174, in pytest_runtest_protocol
        return (yield)
                ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/unittest.py", line 408, in pytest_runtest_protocol
        res = yield
              ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/faulthandler.py", line 85, in pytest_runtest_protocol
        return (yield)
                ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
        res = hook_impl.function(*args)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/runner.py", line 114, in pytest_runtest_protocol
        runtestprotocol(item, nextitem=nextitem)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/runner.py", line 133, in runtestprotocol
        reports.append(call_and_report(item, "call", log))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/runner.py", line 228, in call_and_report
        report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
        return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
        return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 138, in _multicall
        raise exception.with_traceback(exception.__traceback__)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/tmpdir.py", line 316, in pytest_runtest_makereport
        rep = yield
              ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
        teardown.throw(exception)  # type: ignore[union-attr]
        ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/skipping.py", line 269, in pytest_runtest_makereport
        rep = yield
              ^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
        res = hook_impl.function(*args)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/runner.py", line 372, in pytest_runtest_makereport
        return TestReport.from_item_and_call(item, call)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/reports.py", line 364, in from_item_and_call
        longrepr = item.repr_failure(excinfo)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/python.py", line 1877, in repr_failure
        return self._repr_failure_py(excinfo, style=style)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/nodes.py", line 497, in _repr_failure_py
        return excinfo.getrepr(
               ^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 698, in getrepr
        return fmt.repr_excinfo(self)
               ^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 1057, in repr_excinfo
        reprtraceback = self.repr_traceback(excinfo_)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 981, in repr_traceback
        entries = [
                  ^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 982, in <listcomp>
        self.repr_traceback_entry(entry, excinfo if last == entry else None)
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 920, in repr_traceback_entry
        source = self._getentrysource(entry)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 822, in _getentrysource
        source = entry.getsource(self.astcache)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/code.py", line 259, in getsource
        astnode, _, end = getstatementrange_ast(
                          ^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/_pytest/_code/source.py", line 199, in getstatementrange_ast
        block_finder.started = source.lines[start][0].isspace()
                               ~~~~~~~~~~~~~~~~~~~^^^
    IndexError: string index out of range
  2. solaluset commented on Feb 9, 2024

    @solaluset
    ContributorAuthor

    This was because incomplete_input (python/cpython@cd6e0a0) was causing an error in my module. Still, pytest was of no help until I monkey patched it to check if the string actually contains something.

  3. added
    type: bug
    on Feb 17, 2024
  4. added a commit that references this issue on Feb 17, 2024
    8f949de
  5. bluetech commented on Feb 17, 2024

    @bluetech
    Member

    I submitted a fix in #11996, maybe you can verify that it fixes the issue.

  6. solaluset commented on Feb 17, 2024

    @solaluset
    ContributorAuthor

    @bluetech I confirm that it works

  7. added a commit that references this issue on Feb 17, 2024
    9f13d41
  8. added a commit that references this issue on Apr 9, 2024
    a6a176b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions