Running flake8 with Python unit tests

458 views
Skip to first unread message

Dave Buchfuhrer

unread,
Jul 28, 2016, 9:26:09 PM7/28/16
to Pants Developers
Is there any way to run flake8 as part of Python unit tests? I see that there's some checkstyle code that mentions it, but I'm having trouble figuring out how to trigger it.

Kris Wilson

unread,
Jul 28, 2016, 10:35:11 PM7/28/16
to Dave Buchfuhrer, Pants Developers
I don't believe so. your best bet would probably be a flake8-specific contrib task/backend that you could layer in alongside or instead of checkstyle.

an alternative, but cruder approach might be to leverage a pytest plugin. theoretically, you could inject something like https://pypi.python.org/pypi/pytest-flake8 into the test chroot and then pass the requisite args to trigger that in pytest via either passthru args (`./pants test <target> -- -vvs --flake8` etc) or by setting the `--test-pytest-options` option in your repo-specific pants.ini. resolving the todo here would unblock a path to test dep injection more generally.

Dave Buchfuhrer

unread,
Jul 29, 2016, 2:59:25 AM7/29/16
to Kris Wilson, Pants Developers
How do I run the checkstyle? I spent a long time searching through the code and can't figure out how to trigger it as part of my build. I'd be happy to put in the work to build flake8 in a similar way but I'm too lost right now.

Kris Wilson

unread,
Jul 29, 2016, 3:27:39 AM7/29/16
to Dave Buchfuhrer, Pants Developers
I think you just need to install this backend: https://pypi.python.org/pypi/pantsbuild.pants.contrib.python.checks

via the process in the docs here: http://pantsbuild.github.io/install.html

(and def feel free to file bugs if any of it isn't clear from the docs or could be clearer)

Dave Buchfuhrer

unread,
Jul 29, 2016, 3:36:46 AM7/29/16
to Kris Wilson, Pants Developers
That worked, thanks! It's catching some stuff that flake8 didn't too, so a bonus there. I'll poke around it now and see about the documentation too.
Reply all
Reply to author
Forward
0 new messages