Skip to content

Fix IndexError when coverage reports extensionless files#261

Open
reese-allison wants to merge 1 commit intotarpas:mainfrom
reese-allison:fix-extensionless-file-crash
Open

Fix IndexError when coverage reports extensionless files#261
reese-allison wants to merge 1 commit intotarpas:mainfrom
reese-allison:fix-extensionless-file-crash

Conversation

@reese-allison
Copy link

When coverage.py reports files without extensions (e.g., Dockerfile, Makefile), SourceTree.get_file() crashes:

IndexError: list index out of range

at testmon/testmon_core.py line 93.

Cause: filename.rsplit(".", 1) returns a single-element list when the filename has no dot, so [1] raises IndexError.

Fix: Check for the presence of a dot before attempting to extract the extension.

Reproduction: Create a test that calls compile() with an extensionless filename, then run pytest --testmon.

When coverage.py reports files without extensions (Dockerfile, Makefile, etc.),
SourceTree.get_file() crashes with IndexError because rsplit(".", 1) returns
a single-element list when there's no dot in the filename.

Handle the case by checking for a dot before attempting to extract the extension.
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.

1 participant