Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it compatible with latest flake8 #96

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions pytest_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from io import BytesIO, TextIOWrapper

from flake8.main import application
from flake8.options import config
from flake8.options.parse_args import parse_args

import pytest

Expand Down Expand Up @@ -213,21 +213,12 @@ def check_file(path, flake8ignore, maxlength, maxdoclenght, maxcomplexity,
if statistics:
args += ['--statistics']
app = application.Application()
prelim_opts, remaining_args = app.parse_preliminary_options(args)
config_finder = config.ConfigFileFinder(
app.program,
prelim_opts.append_config,
config_file=prelim_opts.config,
ignore_config_files=prelim_opts.isolated,
)
Comment on lines -217 to -222
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #88 the code is kept 🤔 but from the commit where they change they remove it.

app.find_plugins(config_finder)
app.register_plugin_options()
app.parse_configuration_and_cli(config_finder, remaining_args)
app.plugins, app.options = parse_args(args)
if flake8ignore:
app.options.ignore = flake8ignore
app.make_formatter() # fix this
app.make_guide()
app.make_file_checker_manager()
app.make_file_checker_manager([])
app.run_checks([str(path)])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, correct me if I'm wrong because I'm not an expert. I am wondering how you know that run_checks() needs that one argument ([str(path)]), because in run_checks() is not other argument than self.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I might have a wrong setup will retry

app.formatter.start()
app.report_errors()
Expand Down
9 changes: 4 additions & 5 deletions test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Unit tests for flake8 pytest plugin."""
from __future__ import print_function

import py
import pytest

pytest_plugins = "pytester",
Expand Down Expand Up @@ -44,8 +43,8 @@ def test_default_flake8_ignores(self, testdir):

[flake8]
ignore = E203
*.py E300
tests/*.py ALL E203 # something
E300
ALL E203
""")
testdir.tmpdir.ensure("xy.py")
testdir.tmpdir.ensure("tests/hello.py")
Expand Down Expand Up @@ -164,13 +163,13 @@ def test_unicode_error(testdir):
x = testdir.tmpdir.join("x.py")
import codecs
f = codecs.open(str(x), "w", encoding="utf8")
f.write(py.builtin._totext("""
f.write("""
# coding=utf8

accent_map = {
u'\\xc0': 'a', # À -> a non-ascii comment crashes it
}
""", "utf8"))
""")
f.close()
# result = testdir.runpytest("--flake8", x, "-s")
# result.stdout.fnmatch_lines("*non-ascii comment*")
Expand Down