|
15 | 15 | from __future__ import print_function
|
16 | 16 |
|
17 | 17 | import os
|
| 18 | +import subprocess |
18 | 19 | import sys
|
19 | 20 |
|
20 |
| -from flake8.api.legacy import get_style_guide |
21 | 21 | import pytest
|
22 | 22 |
|
23 | 23 |
|
24 | 24 | @pytest.mark.flake8
|
25 | 25 | @pytest.mark.linter
|
26 | 26 | def test_flake8():
|
27 |
| - style_guide = get_style_guide( |
28 |
| - exclude=['conf.py'], |
29 |
| - ignore=[ |
30 |
| - 'C402', # ignore presence of unnecessary generators |
31 |
| - 'C405', # ignore presence of unnecessary literals |
32 |
| - 'C407', # ignore presence of unnecessary comprehensions |
33 |
| - 'C408', # ignore presence of unnecessary tuple/list/dict |
34 |
| - 'D', # ignore documentation related warnings |
35 |
| - 'F401', # ignore presence of unused imports |
36 |
| - 'F841', # ignore presence of unused variables |
37 |
| - 'I', # ignore import order related warnings |
38 |
| - 'N802', # ignore presence of upper case in function names |
39 |
| - 'W504', # ignore line breaks after binary operator (new rule added in 2018) |
40 |
| - ], |
41 |
| - max_line_length=200, |
42 |
| - max_complexity=10, |
43 |
| - show_source=True, |
| 27 | + # flake8 doesn't have a stable public API as of ver 6.1.0. |
| 28 | + # See: https://flake8.pycqa.org/en/latest/user/python-api.html |
| 29 | + # Calling through subprocess is the most stable way to run it. |
| 30 | + |
| 31 | + # We still need to support Python 2.7, so we can't use run() |
| 32 | + ret_code = subprocess.call( |
| 33 | + [sys.executable, "-m", "flake8"], |
| 34 | + cwd=os.path.dirname(os.path.dirname(__file__)), |
44 | 35 | )
|
45 |
| - |
46 |
| - stdout = sys.stdout |
47 |
| - sys.stdout = sys.stderr |
48 |
| - # implicitly calls report_errors() |
49 |
| - report = style_guide.check_files([ |
50 |
| - os.path.dirname(os.path.dirname(__file__)), |
51 |
| - ]) |
52 |
| - sys.stdout = stdout |
53 |
| - |
54 |
| - if report.total_errors: |
55 |
| - # output summary with per-category counts |
56 |
| - print() |
57 |
| - report._application.formatter.show_statistics(report._stats) |
58 |
| - print( |
59 |
| - 'flake8 reported {report.total_errors} errors' |
60 |
| - .format(**locals()), file=sys.stderr) |
61 |
| - |
62 |
| - assert not report.total_errors, \ |
63 |
| - 'flake8 reported {report.total_errors} errors'.format(**locals()) |
| 36 | + assert 0 == ret_code, "flake8 found violations" |
0 commit comments