Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom error formatting #93

Merged
merged 1 commit into from
Aug 10, 2020
Merged

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