Skip to content

Commit

Permalink
Implement collect() for Flake8Item
Browse files Browse the repository at this point in the history
Solves NotImplementedError on python3.8 pytest 6.1 when run on an __init__.py
file:

Traceback (most recent call last):
  File "venv/lib/python3.8/site-packages/_pytest/runner.py", line 310, in from_call
    result = func()  # type: Optional[TResult]
  File "venv/lib/python3.8/site-packages/_pytest/runner.py", line 340, in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
  File "venv/lib/python3.8/site-packages/_pytest/nodes.py", line 463, in collect
    raise NotImplementedError("abstract")
NotImplementedError: abstract
  • Loading branch information
coretl committed Oct 20, 2020
1 parent e3c01e9 commit 47853fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pytest_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def reportinfo(self):
ignores = ""
return (self.fspath, -1, "FLAKE8-check%s" % ignores)

def collect(self):
return iter((self,))


class Ignorer:
def __init__(self, ignorelines, coderex=re.compile(r"[EW]\d\d\d")):
Expand Down
6 changes: 6 additions & 0 deletions test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ def test_hello():
result.assert_outcomes(failed=1)


def test_run_on_init_file(testdir):
d = testdir.mkpydir("tests")
result = testdir.runpytest("--flake8", d / "__init__.py")
result.assert_outcomes(passed=1)


@pytest.mark.xfail("sys.platform == 'win32'")
def test_unicode_error(testdir):
x = testdir.tmpdir.join("x.py")
Expand Down

0 comments on commit 47853fc

Please sign in to comment.