pytest-dev/pytest-github-actions-annotate-failures

INTERNALERROR when used with pytest-mypy

Tenzer opened this issue · 2 comments

We are using the pytest-mypy plugin for checking type annotations via Pytest. When trying to set up your plugin for our tests it however throws an exception whenever there's a type error, seemingly because there's no line number associated with the test failure, which trips up this line:
https://github.com/utgwkk/pytest-github-actions-annotate-failures/blob/6cb5788e20f371dee106ab1983c039a195a05d41/pytest_github_actions_annotate_failures/plugin.py#L53

TypeError: unsupported operand type(s) for +=: 'NoneType' and 'int'

I see a couple of different options:

  1. Add an if lineno is not None: before the line linked above. This will result in the test failure being reported against the entire file instead of a specific line. This is already handled in _error_workflow_command which checks if the line number is not-None.
  2. Ignore test failures without a line number entirely.
  3. Fallback to reporting the test failures at line 1 in the file.

Alternately, it might be possible to parse the test failure output from pytest-mypy - a bit like what is done in the try/except block already. I don't know how much work this would be or if it's something you'd be interested in having added. There might be other Pytest plugins which then also would benefit from getting their output handled more intelligently, so it could be a slippery slope.

I'd be happy to help contribute towards whichever solution you think would be best suited.

I think 1 (adding if-statement before the line) is a better option.

I've just released version 0.1.6 containing #22 (fix of this issue). Thank you! @Tenzer