ethereum / eth-hash

The Ethereum hashing function, keccak256, sometimes (erroneously) called sha256 or sha3
MIT License
104 stars 64 forks source link

test_import.py failing #25

Closed jluttine closed 6 years ago

jluttine commented 6 years ago

What was wrong?

Some unit tests in test_import.py fail.

Code that produced the error

$ pytest tests/core/test_import.py 

Full error output

============================================================================================================= test session starts =============================================================================================================
platform linux -- Python 3.6.6, pytest-3.7.4, py-1.5.4, pluggy-0.7.1 -- /nix/store/hy65mn4wjswqih75gfr6g4q3xgqdm325-python3-3.6.6/bin/python3.6m
cachedir: .pytest_cache
rootdir: /home/jluttine/Workspace/eth-hash, inifile: pytest.ini
collected 6 items                                                                                                                                                                                                                             

tests/core/test_import.py::test_import_auto PASSED                                                                                                                                                                                      [ 16%]
tests/core/test_import.py::test_import_auto_empty_crash FAILED                                                                                                                                                                          [ 33%]
tests/core/test_import.py::test_import PASSED                                                                                                                                                                                           [ 50%]
tests/core/test_import.py::test_load_by_env[pycryptodome] FAILED                                                                                                                                                                        [ 66%]
tests/core/test_import.py::test_load_by_env[pysha3] FAILED                                                                                                                                                                              [ 83%]
tests/core/test_import.py::test_load_unavailable_backend_by_env FAILED                                                                                                                                                                  [100%]

================================================================================================================== FAILURES ===================================================================================================================
________________________________________________________________________________________________________ test_import_auto_empty_crash _________________________________________________________________________________________________________

    def test_import_auto_empty_crash():
        from eth_hash.auto import keccak
        with pytest.raises(ImportError, match="None of these hashing backends are installed"):
>           keccak(b'')
E           Failed: DID NOT RAISE <class 'ImportError'>

keccak     = <eth_hash.main.Keccak256 object at 0x7f5c2fdbd6a0>

tests/core/test_import.py:11: Failed
_______________________________________________________________________________________________________ test_load_by_env[pycryptodome] ________________________________________________________________________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f5c2fc39128>, backend = 'pycryptodome'

    @pytest.mark.parametrize(
        'backend',
        [
            'pycryptodome',
            'pysha3',
        ],
    )
    def test_load_by_env(monkeypatch, backend):
        from eth_hash.auto import keccak
        monkeypatch.setenv('ETH_HASH_BACKEND', backend)
        with pytest.raises(ImportError) as excinfo:
>           keccak(b'triggered')
E           Failed: DID NOT RAISE <class 'ImportError'>

backend    = 'pycryptodome'
excinfo    = <[AttributeError("'ExceptionInfo' object has no attribute 'typename'") raised in repr()] ExceptionInfo object at 0x7f5c2fc39828>
keccak     = <eth_hash.main.Keccak256 object at 0x7f5c2fdbd6a0>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f5c2fc39128>

tests/core/test_import.py:29: Failed
__________________________________________________________________________________________________________ test_load_by_env[pysha3] ___________________________________________________________________________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f5c2fbed208>, backend = 'pysha3'

    @pytest.mark.parametrize(
        'backend',
        [
            'pycryptodome',
            'pysha3',
        ],
    )
    def test_load_by_env(monkeypatch, backend):
        from eth_hash.auto import keccak
        monkeypatch.setenv('ETH_HASH_BACKEND', backend)
        with pytest.raises(ImportError) as excinfo:
>           keccak(b'triggered')
E           Failed: DID NOT RAISE <class 'ImportError'>

backend    = 'pysha3'
excinfo    = <[AttributeError("'ExceptionInfo' object has no attribute 'typename'") raised in repr()] ExceptionInfo object at 0x7f5c2fbed2b0>
keccak     = <eth_hash.main.Keccak256 object at 0x7f5c2fdbd6a0>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f5c2fbed208>

tests/core/test_import.py:29: Failed
____________________________________________________________________________________________________ test_load_unavailable_backend_by_env _____________________________________________________________________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f5c2fc39d30>

    def test_load_unavailable_backend_by_env(monkeypatch):
        from eth_hash.auto import keccak
        backend = 'this-backend-will-never-exist'
        monkeypatch.setenv('ETH_HASH_BACKEND', backend)
        with pytest.raises(ValueError) as excinfo:
>           keccak(b'triggered')
E           Failed: DID NOT RAISE <class 'ValueError'>

backend    = 'this-backend-will-never-exist'
excinfo    = <[AttributeError("'ExceptionInfo' object has no attribute 'typename'") raised in repr()] ExceptionInfo object at 0x7f5c2fc39160>
keccak     = <eth_hash.main.Keccak256 object at 0x7f5c2fdbd6a0>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f5c2fc39d30>

tests/core/test_import.py:42: Failed
========================================================================================================== slowest 10 test durations ==========================================================================================================
0.01s call     tests/core/test_import.py::test_import_auto
0.01s call     tests/core/test_import.py::test_import_auto_empty_crash
0.00s setup    tests/core/test_import.py::test_load_by_env[pycryptodome]
0.00s setup    tests/core/test_import.py::test_load_by_env[pysha3]
0.00s teardown tests/core/test_import.py::test_load_by_env[pycryptodome]
0.00s call     tests/core/test_import.py::test_load_by_env[pycryptodome]
0.00s call     tests/core/test_import.py::test_load_unavailable_backend_by_env
0.00s teardown tests/core/test_import.py::test_load_by_env[pysha3]
0.00s call     tests/core/test_import.py::test_load_by_env[pysha3]
0.00s setup    tests/core/test_import.py::test_load_unavailable_backend_by_env
===================================================================================================== 4 failed, 2 passed in 0.07 seconds ======================================================================================================

Environment

# run this:
$ python -m eth_utils

# then copy the output here:
/nix/store/hy65mn4wjswqih75gfr6g4q3xgqdm325-python3-3.6.6/bin/python: No module named eth_utils
carver commented 6 years ago

In general, the tests are not guaranteed to pass unless they are run inside tox which sets up the appropriate environments. I'm not necessarily opposed to doing extra work to have the tests pass in unexpected environments, but running outside of tox may stop working again in the future.

jluttine commented 6 years ago

I'm not familiar with tox. How would I test that the package I installed is working when I don't care about other environments? Typically, I'd run something like py.test tests in the source directory but how is it done with tox in eth-hash?

carver commented 6 years ago

After you do the dev environment setup, you can run the command tox at the shell in the source directory, which will run all the tests.

You can run tox -epy36-core to run just one of the test batches. You can see the available environments with tox -l. Tox defines the environments and test commands that the tests run with tox.ini: https://github.com/ethereum/eth-hash/blob/master/tox.ini