Skip to content

Instantly share code, notes, and snippets.

@cristihainic
Created April 12, 2018 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristihainic/3e3717518b00b7cdd66ba243e7438b37 to your computer and use it in GitHub Desktop.
Save cristihainic/3e3717518b00b7cdd66ba243e7438b37 to your computer and use it in GitHub Desktop.
Unit test that checks for PEP8 faults in a Django project using pytest
import os
import sys
import pycodestyle
from django.conf import settings
class PEP8Error(BaseException):
pass
def error_print(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def test_pep8():
style = pycodestyle.StyleGuide(config_file=os.path.join(settings.BASE_DIR, 'tox.ini'))
py_files = []
for root, dirs, files in os.walk(settings.BASE_DIR):
for file in files:
if file.endswith(".py"):
py_files.append(os.path.join(root, file))
pep8_check = style.check_files(py_files)
if pep8_check.total_errors > 0:
for err in pep8_check.messages:
error_print(err)
raise PEP8Error('PEP8 misconducts have been found; check stderr.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment