Created
July 11, 2018 07:51
-
-
Save emakarov/60ec13dc8b53b53f66be332e65a9bfc0 to your computer and use it in GitHub Desktop.
How to check python coding style automatically via flake8 and isort in django project with unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Coding styles test. | |
You need to install flake8 and isort via pip. | |
pip install flake8 | |
pip install isort | |
Add this test to any of your django apps tests. | |
""" | |
import subprocess | |
from django.test import TestCase | |
class TestCodingStyle(TestCase): | |
""" | |
Test of the code for Flake8 and isort. | |
""" | |
def test_flake8(self): | |
"""Testing the retval of flake8 command to be zero (PEP8 check).""" | |
p = subprocess.Popen('flake8') | |
retval = p.wait() | |
self.assertEqual(retval, 0) | |
def test_isort(self): | |
"""Testing the retval of `isort -rc -c .` command to be zero. (import sort order)""" | |
p = subprocess.Popen('isort -rc -c .', shell=True) | |
retval = p.wait() | |
self.assertEqual(retval, 0) |
strange, since this code is working fine for me. maybe some local file structure issue or python/isort version
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! When running isort, I had to use "shell=False"; otherwise I got this error:
Nothing to do: no files or paths have have been passed in!