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

Improve pytest failure output for mypy #99

Open
GergelyKalmar opened this issue Aug 18, 2020 · 2 comments
Open

Improve pytest failure output for mypy #99

GergelyKalmar opened this issue Aug 18, 2020 · 2 comments

Comments

@GergelyKalmar
Copy link

It seems that the failures for pylint have [pylint] prepended to the filename in the failure output:

image

It would be great to have [mypy] prepended to the filenames of the errors that belong to mypy (the second list of errors on the picture above). Or is this something that can be somehow configured in mypy and/or somewhere in pytest?

@dmtucker
Copy link
Collaborator

This should work in a conftest.py:

def custom_file_reportinfo(file_item):
    return (
        file_item.fspath,
        None,
        '[mypy] ' + file_item.config.invocation_dir.bestrelpath(
            file_item.fspath,
        ),
    )


def pytest_configure(config):
    plugin = config.pluginmanager.getplugin("mypy")
    plugin.MypyFileItem.reportinfo = custom_file_reportinfo

Let's leave this open until a test for that is added (to ensure continued support) or a better API is proposed.

@GergelyKalmar
Copy link
Author

This indeed does work well, thank you! Could we consider to make this the default option? I've found it to be quite useful to see which plugin a given failure belongs to.

Other plugins I use seem to do this by default (somewhat):

Of course, as an alternative I'll just patch each of them with an improved version of your custom reportinfo function, hehe:

def reportinfo_unifier(prefix):
    def reportinfo(file_item):
        return (
            file_item.fspath,
            None,
            prefix + ' ' + file_item.config.invocation_dir.bestrelpath(file_item.fspath),
        )
    return reportinfo


def pytest_configure(config):
    plugin = config.pluginmanager.getplugin
    plugin('mypy').MypyFileItem.reportinfo = reportinfo_unifier(prefix='[mypy]')
    plugin('isort').IsortItem.reportinfo = reportinfo_unifier(prefix='[isort]')

Dynamic languages are such fun!

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

No branches or pull requests

2 participants