Skip to content

safeguard against IndexError - #298

Merged
auvipy merged 3 commits into
Teemu:mainfrom
brondsem:avoid_possible_indexerror
Oct 10, 2025
Merged

safeguard against IndexError#298
auvipy merged 3 commits into
Teemu:mainfrom
brondsem:avoid_possible_indexerror

Conversation

@brondsem

Copy link
Copy Markdown
Contributor

I got this error (also reported by others at #190)

INTERNALERROR>   File "/Users/brondsem/dev/pytest-sugar/pytest_sugar.py", line 482, in pytest_runtest_logreport
INTERNALERROR>     self.insert_progress(report)
INTERNALERROR>   File "/Users/brondsem/dev/pytest-sugar/pytest_sugar.py", line 359, in insert_progress
INTERNALERROR>     append_string = get_progress_bar()
INTERNALERROR>                     ^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/Users/brondsem/dev/pytest-sugar/pytest_sugar.py", line 350, in get_progress_bar
INTERNALERROR>     progressbar += colored(bar[block], theme, on_color)
INTERNALERROR>                            ~~~^^^^^^^
INTERNALERROR> IndexError: string index out of range

I was able to reproduce it with @flaky. In most situations everything runs fine, but with a large # of tests I was able to reproduce. Other plugins/configs might be able to trigger it also, not sure. Here's the flaky example:

import pytest
from flaky import flaky

@pytest.mark.parametrize("x", range(200))
def test_lots1(x):
    assert True

@flaky
def test_flaky():
    assert False

@pytest.mark.parametrize("x", range(80))
def test_lots2(x):
    assert True

So I've added a simple safeguard to avoid the error.

@sweh

sweh commented Oct 9, 2025

Copy link
Copy Markdown

I'm getting the same error message in my project. This fix resolves it. Could the maintainer please merge and release it?

@auvipy auvipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please also add the flaky example as tests to verify this?

@brondsem

brondsem commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Test added

@auvipy
auvipy merged commit e42957a into Teemu:main Oct 10, 2025
4 checks passed
@auvipy

auvipy commented Oct 10, 2025

Copy link
Copy Markdown
Collaborator

thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants