Skip to content

Conversation

dmtucker
Copy link
Collaborator

@dmtucker dmtucker commented Aug 2, 2020

This adds a new plugin attribute (file_error_formatter) that defines a callable which is invoked when mypy finds errors in a file.
Here is an example (similar to the new test) of how it can be used to resolve #90 (cc: @markusschmaus, @jduprey):

import py


def custom_file_error_formatter(item, results, errors):
    """Include the file path before each reported error."""
    return '\n'.join(
        '{path}:{error}'.format(
            path=py.path.local('.').bestrelpath(item.fspath),
            error=error,
        )   
        for error in errors
    )


def pytest_configure(config):
    plugin = config.pluginmanager.getplugin('mypy')
    plugin.file_error_formatter = custom_file_error_formatter

@dmtucker dmtucker added this to the 0.7.0 milestone Aug 2, 2020
@dmtucker dmtucker merged commit 551f25c into realpython:master Aug 10, 2020
@dmtucker dmtucker deleted the output-format branch August 10, 2020 02:26
@jduprey
Copy link

jduprey commented Aug 24, 2020

Thank you! I look forward to trying it out.

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.

Don't strip filename from errors

2 participants