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

Got exception when running main on a __init__.py file with flake8 installed #4591

Closed
will133 opened this issue Jan 3, 2019 · 1 comment
Closed

Comments

@will133
Copy link
Contributor

will133 commented Jan 3, 2019

Was running pytest 3.10 and now when I try to just run on a module's __init__.py, I'd get an error such as:

$ pytest tests/__init__.py
========================================================= test session starts =========================================================
platform linux -- Python 3.6.7, pytest-3.10.0, py-1.7.0, pluggy-0.8.0
rootdir: /auto/cnvtvws/wlee/fcnvt/blahblah, inifile: setup.cfg
plugins: flake8-1.0.2
collected 0 items / 1 errors

=============================================================== ERRORS ================================================================
__________________________________________________________ ERROR collecting  __________________________________________________________
/myenv/miniconda/envs/test_pytest/lib/python3.6/site-packages/_pytest/runner.py:212: in __init__
    self.result = func()
/myenv/miniconda/envs/test_pytest/lib/python3.6/site-packages/_pytest/runner.py:272: in <lambda>
    call = CallInfo(lambda: list(collector.collect()), "collect")
/myenv/miniconda/envs/test_pytest/lib/python3.6/site-packages/_pytest/main.py:478: in collect
    for x in self._collect(arg):
/myenv/miniconda/envs/test_pytest/lib/python3.6/site-packages/_pytest/main.py:568: in _collect
    yield next(m[0].collect())
/myenv/miniconda/envs/test_pytest/lib/python3.6/site-packages/_pytest/nodes.py:429: in collect
    raise NotImplementedError("abstract")
E   NotImplementedError: abstract
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================= 1 error in 0.17 seconds =======================================================

It seems like there's new code in _pytest/main.py:563 that has something like:

            # If __init__.py was the only file requested, then the matched node will be
            # the corresponding Package, and the first yielded item will be the __init__
            # Module itself, so just use that. If this special case isn't taken, then all
            # the files in the package will be yielded.
            if argpath.basename == "__init__.py":
                yield next(m[0].collect())
                return

It turns out the m is a list from the previous collect where the first item is actually a Flake8Item. It would not work when you call collect on it. I'm not sure the intention of this extra collect, but should it check if the item isinstance a package?

pip list:

Package        Version
-------------- ----------
atomicwrites   1.2.1
attrs          18.2.0
certifi        2018.10.15
flake8         3.6.0
mccabe         0.6.1
more-itertools 4.3.0
pip            18.1
pluggy         0.8.0
py             1.7.0
pycodestyle    2.4.0
pyflakes       2.0.0
pytest         3.10.0
pytest-flake8  1.0.2
setuptools     40.5.0
six            1.11.0
wheel          0.32.2

I'm using conda to install this:

$ conda create -n test_pytest python=3.6 pytest pytest-flake8
@blueyed
Copy link
Contributor

blueyed commented Jan 4, 2019

Duplicate of #4344 ?
(closing already, but feel free to re-open)

@blueyed blueyed closed this as completed Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants