Skip to content

Instantly share code, notes, and snippets.

@emakarov
Created July 11, 2018 07:51
Show Gist options
  • Save emakarov/60ec13dc8b53b53f66be332e65a9bfc0 to your computer and use it in GitHub Desktop.
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
"""
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)
@emakarov
Copy link
Author

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