Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Pytest Failing (eth2spec not found, Namespace has no attribute, import file mismatch) #1218

Closed
wschwab opened this issue Oct 10, 2019 · 23 comments

Comments

@wschwab
Copy link

wschwab commented Oct 10, 2019

  • Trinity version: 0.1.0a29
  • OS: Linux (Debian 10)
  • Python version (output of python --version): Python 3.7.3
  • Environment (output of pip freeze):
    aiohttp==3.6.0
    alabaster==0.7.12
    apipkg==1.5
    argcomplete==1.10.0
    argh==0.26.2
    asn1crypto==1.0.1
    async-exit-stack==1.0.1
    async-generator==1.10
    async-lru==0.1.0
    async-timeout==3.0.1
    asyncio-cancel-token==0.2.0
    atomicwrites==1.3.0
    attrdict==2.0.1
    attrs==19.2.0
    Babel==2.7.0
    backcall==0.1.0
    base58==1.0.3
    bleach==3.1.0
    bloom-filter==1.3
    bumpversion==0.5.3
    cached-property==1.5.1
    cachetools==3.1.1
    certifi==2019.9.11
    cffi==1.12.3
    chardet==3.0.4
    Click==7.0
    coincurve==10.0.0
    colorama==0.4.1
    coverage==4.5.4
    cryptography==2.6.1
    cytoolz==0.10.0
    decorator==4.4.0
    docopt==0.6.2
    docutils==0.15.2
    eth-abi==1.3.0
    eth-account==0.2.3
    eth-bloom==1.0.3
    eth-hash==0.2.0
    eth-keyfile==0.5.1
    eth-keys==0.2.4
    eth-rlp==0.1.2
    eth-typing==2.1.0
    eth-utils==1.7.0
    execnet==1.7.1
    factory-boy==2.11.1
    Faker==2.0.2
    fastecdsa==1.7.4
    flake8==3.5.0
    flake8-bugbear==18.8.0
    hexbytes==0.2.0
    hypothesis==4.40.0
    idna==2.7
    ifaddr==0.1.6
    imagesize==1.1.0
    incremental==17.5.0
    ipython==7.8.0
    ipython-genutils==0.2.0
    jedi==0.15.1
    Jinja2==2.10.3
    jsonschema==3.0.1
    lahja==0.14.5
    libp2p==0.1.1
    lru-dict==1.1.6
    lxml==4.4.1
    MarkupSafe==1.1.1
    mccabe==0.6.1
    milagro-bls-binding==0.1.3
    more-itertools==7.2.0
    multiaddr==0.0.8
    multidict==4.5.2
    mypy==0.730
    mypy-extensions==0.4.2
    netaddr==0.7.19
    netdisco==2.6.0
    netifaces==0.10.9
    outcome==1.0.0
    packaging==19.2
    parsimonious==0.8.1
    parso==0.5.1
    pathtools==0.1.2
    pexpect==4.7.0
    pickleshare==0.7.5
    pkginfo==1.5.0.1
    pluggy==0.7.1
    plyvel==1.0.5
    prompt-toolkit==2.0.10
    protobuf==3.9.0
    ptyprocess==0.6.0
    py==1.8.0
    py-ecc==1.7.1
    py-evm==0.3.0a7
    pycodestyle==2.3.1
    pycparser==2.19
    pycryptodome==3.9.0
    pyethash==0.1.27
    pyflakes==1.6.0
    Pygments==2.4.2
    pymultihash==0.8.2
    pyparsing==2.4.2
    pyrsistent==0.15.4
    pysha3==1.0.2
    pytest==3.6.4
    pytest-aiohttp==0.3.0
    pytest-asyncio==0.10.0
    pytest-cov==2.5.1
    pytest-mock==1.10.4
    pytest-randomly==3.0.0
    pytest-trio==0.5.2
    pytest-watch==4.2.0
    pytest-xdist==1.18.1
    python-dateutil==2.8.0
    python-snappy==0.5.4
    pytz==2019.3
    PyYAML==5.1.2
    readme-renderer==24.0
    requests==2.22.0
    requests-toolbelt==0.9.1
    rlp==1.1.0
    rpcudp==3.0.0
    ruamel.yaml==0.15.98
    six==1.12.0
    sniffio==1.1.0
    snowballstemmer==2.0.0
    sortedcontainers==2.1.0
    Sphinx==1.7.9
    sphinx-rtd-theme==0.4.3
    sphinxcontrib-asyncio==0.2.0
    sphinxcontrib-websupport==1.1.2
    SQLAlchemy==1.3.10
    sqlalchemy-stubs==0.1
    ssz==0.1.5
    termcolor==1.1.0
    text-unidecode==1.3
    toml==0.10.0
    toolz==0.10.0
    towncrier==19.2.0
    tox==2.7.0
    tqdm==4.36.1
    traitlets==4.3.3
    trie==1.4.0
    trinity==0.1.0a29
    trio==0.11.0
    trio-typing==0.2.0
    twine==2.0.0
    typed-ast==1.4.0
    typing-extensions==3.7.4
    u-msgpack-python==2.5.2
    uPnPClient==0.0.8
    urllib3==1.25.6
    uvloop==0.11.2
    varint==1.0.2
    virtualenv==16.7.5
    watchdog==0.9.0
    wcwidth==0.1.7
    web3==4.4.1
    webencodings==0.5.1
    websockets==5.0.1
    yarl==1.3.0
    zeroconf==0.23.0

What is wrong?

Local runs of Pytest fail. I've run a variety of commands, but will focus on plain pytest here.

On issue is connected to a module eth2spec which is referenced twice in one script, but never appears in the project:

__________________________________________________________ ERROR collecting scripts/test_transition.py ___________________________________________________________
ImportError while importing test module '/home/x/code/trinity/scripts/test_transition.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
scripts/test_transition.py:16: in <module>
    from eth2spec.fuzzing import decoder
E   ModuleNotFoundError: No module named 'eth2spec'

Another is a problem with Namespace. @veox correctly identified that the issue is somewhere in the eth2 tests; --ignore=tests/eth2 circumvents these issues. I get 8 of them, but will put the output of one of them for reference:

______________________________________________________ ERROR collecting tests/eth2/fixtures/test_genesis.py ______________________________________________________
tests/eth2/fixtures/test_genesis.py:10: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture
    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
    _keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}
eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'

Lastly:

_________________________________________________________ ERROR collecting tests/libp2p/bcc/test_sync.py _________________________________________________________
import file mismatch:
imported module 'test_sync' has this __file__ attribute:
  /home/x/code/trinity/tests/core/p2p-proto/test_sync.py
which is not the same as the test file we want to collect:
  /home/x/code/trinity/tests/libp2p/bcc/test_sync.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

.pyc files can't be removed, or more precisely, even if removed, will be autogenerated by Pytest when run.

tox is also failing, but the output is massive. If anyone wants to see it, I can post it.

@ralexstokes
Copy link
Member

@wschwab thanks for opening this issue.

this is some utility code that got merged from our recent work on eth2 interop.

i'm actually inclined to just remove this; if not, it will need some work to patch it up

thoughts @lithp ?

@ralexstokes
Copy link
Member

@ChihChengLiang @NIC619 do you see the error above w/ the duplicate test name? i'd suggest we just rename one of them, iirc we had this problem before

@ralexstokes
Copy link
Member

@wschwab have you tried running the eth2 tests after you have the fixtures installed? i'm having some trouble replicating that error w/ Namespace.

@ChihChengLiang
Copy link
Contributor

do you see the error above w/ the duplicate test name?

I didn't see this error when running pytest locally.

@NIC619
Copy link
Contributor

NIC619 commented Oct 25, 2019

do you see the error above w/ the duplicate test name?

I do, with plain pytest.

@ChihChengLiang
Copy link
Contributor

do you see the error above w/ the duplicate test name?

Ah, ... I saw it now. My eyes 🙈

@wschwab
Copy link
Author

wschwab commented Nov 7, 2019

@ralexstokes Sorry, just got back around to this.

have you tried running the eth2 tests after you have the fixtures installed?

Could you explain what you mean by 'the fixtures'?

@ralexstokes
Copy link
Member

@wschwab yep, i mean the cross-client consensus tests we have in place for both eth1 and eth2. the things that are installed as git submodules, e.g. $ git submodule should list them

so generally, you'll do a fresh clone of the repo and then do a submodule initialization which will pull down even more test data we use for cross-client compatibility. once you have all of this then you should be able to run any test

@wschwab
Copy link
Author

wschwab commented Nov 7, 2019

Thanks for explaining. git submodule turns up eth2-fixtures and fixtures, though I haven't updated them for a couple of weeks (unless a regular fetch from master would do that), and I can confirm that this gets rid of the Namespace error, though not the eth2spec error, nor the test_sync error.

@ralexstokes
Copy link
Member

@wschwab pretty sure you need to do an explicit git submodule update to update the fixtures data

re-pinging @lithp re: the eth2spec thing -- i think we should just remove that code

@ChihChengLiang @NIC619 did we ever fix the duplicate test name?

@lithp
Copy link
Contributor

lithp commented Nov 7, 2019

Yeah, sorry about the eth2spec problem. scripts/test_transition.py was useful during interop but I shouldn't have merged it in, I think you're right @ralexstokes that it's fine to remove it and drop the dependency!

@ChihChengLiang
Copy link
Contributor

@ralexstokes The duplicate test name issue is addressed.

@ralexstokes
Copy link
Member

@wschwab i think we have addressed all of the above issues on the remote's end... want to try again and report what you find?

@wschwab
Copy link
Author

wschwab commented Nov 12, 2019

Sorry for the delay - I've been a bit swamped.

Strange. I did a pull to update master, and updated the submodules (git submodules update), and still get the errors. I have a nagging suspicion that this is some (embarrassing) human error on my end. (I get this a lot.) Dumping errors from pytest:

======================================================================= ERRORS ========================================================================
____________________________________________ ERROR collecting tests/eth2/fixtures/test_epoch_processing.py ____________________________________________
tests/eth2/fixtures/test_epoch_processing.py:12: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture

    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
    _keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}
eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'
________________________________________________ ERROR collecting tests/eth2/fixtures/test_genesis.py _________________________________________________
tests/eth2/fixtures/test_genesis.py:10: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture
    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
    _keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}
eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'
_______________________________________________ ERROR collecting tests/eth2/fixtures/test_operations.py _______________________________________________
tests/eth2/fixtures/test_operations.py:13: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture
    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
_keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}
eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'
_________________________________________________ ERROR collecting tests/eth2/fixtures/test_sanity.py _________________________________________________
tests/eth2/fixtures/test_sanity.py:13: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture
    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
    _keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}

eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'
_______________________________________________ ERROR collecting tests/eth2/fixtures/test_shuffling.py ________________________________________________
tests/eth2/fixtures/test_shuffling.py:10: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture
    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
    _keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}
eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'
_______________________________________________ ERROR collecting tests/eth2/fixtures/test_ssz_static.py _______________________________________________
tests/eth2/fixtures/test_ssz_static.py:10: in pytest_generate_tests
    generate_pytests_from_eth2_fixture(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:234: in generate_pytests_from_eth2_fixture
    eth2_fixture_request = _read_request_from_metafunc(metafunc)
eth2/beacon/tools/fixtures/test_generation.py:119: in _read_request_from_metafunc
    _keep_first_some, request, {"config_types": _eth2_config_from(metafunc)}
eth2/beacon/tools/fixtures/test_generation.py:83: in _eth2_config_from
    config_str = metafunc.config.option.config
E   AttributeError: 'Namespace' object has no attribute 'config'

@ralexstokes
Copy link
Member

ralexstokes commented Nov 12, 2019

looks like an issue w/ the fixtures data? what is the output of git submodule update and just git submodule?

@wschwab
Copy link
Author

wschwab commented Nov 12, 2019

git submodule update: no output
git submodule:

 ae6dd9011df05fab8c7e651c09cf9c940973bf81 eth2-fixtures (v0.8.3)
 cfbcd15f91d4d6e1785d9cae5c5c37f47e8bad46 fixtures (PoC6-2242-gcfbcd15f9)

@ralexstokes
Copy link
Member

and you do have the files under eth-fixtures, right?

@wschwab
Copy link
Author

wschwab commented Nov 13, 2019

Maybe this is the issue? At least in the top directory I have eth2-fixtures and fixtures, but no eth-fixtures, though this seems consistent with the repo. Where should eth-fixtures be?

@ralexstokes
Copy link
Member

@wschwab sorry! typo, it is just fixtures.

you could move to another directory and try a fresh clone/install to see if you have some local state that is botching things?

@wschwab
Copy link
Author

wschwab commented Nov 17, 2019

On it. I also suspect that this is a local issue.

@wschwab
Copy link
Author

wschwab commented Nov 17, 2019

Okay. Fresh install turns up a new bug during collection:

==================================== ERRORS ====================================
________________________ ERROR collecting test session _________________________
trin_venv/lib/python3.7/site-packages/_pytest/config/__init__.py:451: in _importconftest
    return self._conftestpath2mod[key]
E   KeyError: PosixPath('/home/x/code/trinity/tests/libp2p/bcc/conftest.py')

During handling of the above exception, another exception occurred:
trin_venv/lib/python3.7/site-packages/_pytest/config/__init__.py:457: in _importconftest
    mod = conftestpath.pyimport()
trin_venv/lib/python3.7/site-packages/py/_path/local.py:701: in pyimport
    __import__(modname)
trin_venv/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:142: in exec_module
    exec(co, module.__dict__)
tests/libp2p/bcc/conftest.py:6: in <module>
    from trinity.tools.bcc_factories import NodeFactory
trinity/tools/bcc_factories.py:1: in <module>
    from eth2.beacon.tools.factories import BeaconChainFactory
eth2/beacon/tools/factories.py:5: in <module>
    import factory
E   ModuleNotFoundError: No module named 'factory'

During handling of the above exception, another exception occurred:
trin_venv/lib/python3.7/site-packages/py/_path/common.py:377: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
trin_venv/lib/python3.7/site-packages/py/_path/common.py:429: in gen
    for p in self.gen(subdir):
trin_venv/lib/python3.7/site-packages/py/_path/common.py:429: in gen
    for p in self.gen(subdir):
trin_venv/lib/python3.7/site-packages/py/_path/common.py:418: in gen
    dirs = self.optsort([p for p in entries
trin_venv/lib/python3.7/site-packages/py/_path/common.py:419: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
trin_venv/lib/python3.7/site-packages/_pytest/main.py:608: in _recurse
    ihook = self.gethookproxy(dirpath)
trin_venv/lib/python3.7/site-packages/_pytest/main.py:426: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
trin_venv/lib/python3.7/site-packages/_pytest/config/__init__.py:429: in _getconftestmodules
    mod = self._importconftest(conftestpath)
trin_venv/lib/python3.7/site-packages/_pytest/config/__init__.py:465: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: (local('/home/x/code/trinity/tests/libp2p/bcc/conftest.py'), (<class 'ModuleNotFoundError'>, ModuleNotFoundError("No module named 'factory'"), <traceback object at 0x7f332d1c8d48>))
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 14.01s ===============================

poking around in the codebase suggests that eth2/beacon/tools/factories.py doesn't import the factory-boy library, and the code in this script doesn't follow the try/except pattern used elsewhere, for example trinity/tools/bcc_factories.py:

try:
    import factory  # noqa: F401 
except ImportError:
    raise ImportError("The `p2p.tools.factories` module requires the `factory-boy` library")

This was found running the whole suite (plain old pytest). tox comes back clean running the 3.7 suite.

@wschwab
Copy link
Author

wschwab commented Nov 19, 2019

The thread seems to have gone stale - as the main issue is most likely resolved, if there's no response here, I'll close the issue.

@ralexstokes
Copy link
Member

@wschwab i think we are good to close :) if you are still having issues w/ installation, feel free to move to the gitter channel for trinity -- help can be found there

@wschwab wschwab closed this as completed Nov 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants