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 #26

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

Improve pytest failure output #26

GergelyKalmar opened this issue Aug 18, 2020 · 2 comments

Comments

@GergelyKalmar
Copy link

It seems that tools like pylint use [pylint] <filename> as the header of failed tests:

image

It would be excellent if pytest-isort could do it similarly instead of using isort-check in each header and noting the filename in the first line as ERROR: <filename> Imports are incorrectly sorted..

@stephrdev
Copy link
Owner

Interesting point, I checked other plugins I use and it seems like there is no "standard". pytest-black has a fixed string too, pytest-flake8 reports the ignored checks. I'm not sure if we should change it as it make break users code/infrastructure in case they check for the "isort-check" string in stdout. World is weird sometimes ;-)

@GergelyKalmar
Copy link
Author

Fair enough. Maybe I'll just create a pytest plugin to normalize this :).

def unified_reportinfo(item, prefix):
    def reportinfo():
        return (item.fspath, None, prefix + item.config.invocation_dir.bestrelpath(item.fspath))
    return reportinfo
def pytest_collection_modifyitems(config, items):
    for item in items:
        source = item.nodeid.split('::')[-1].lower()
        if source in ['isort', 'mypy', 'pylint']:
            item.reportinfo = unified_reportinfo(item=item, prefix=f'[{source}] ')

Works like magic! I wish there was a nicer way than parsing the nodeid, but I suppose you don't plan to change that anytime soon given that it may break things too.

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

No branches or pull requests

2 participants