OpenZeppelin / cairo-contracts

OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup
https://docs.openzeppelin.com/contracts-cairo
MIT License
823 stars 335 forks source link

Test failure when following the README #93

Closed poolpitako closed 2 years ago

poolpitako commented 2 years ago

I have followed the README file and when I try to run tests with pytest I get the following error:

(env) user@users-MBP cairo-contracts % pytest
========================================================= test session starts =========================================================
platform darwin -- Python 3.8.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/user/dev/cairo-contracts
plugins: web3-5.24.0, hypothesis-6.24.0, eth-brownie-1.17.1, xdist-1.34.0, forked-1.3.0
collected 0 items / 5 errors                                                                                                          

=============================================================== ERRORS ================================================================
_______________________________________________ ERROR collecting tests/test_Account.py ________________________________________________
ImportError while importing test module '/Users/user/dev/cairo-contracts/tests/test_Account.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.8.7/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_Account.py:3: in <module>
    from starkware.starknet.testing.starknet import Starknet
E   ModuleNotFoundError: No module named 'starkware'

shouldn't nile install take care of the dependencies?

martriay commented 2 years ago

Did you run nile init or nile install?

On Tue, 30 Nov 2021 at 12:48 poolpitako @.***> wrote:

I have followed the README file and when I try to run tests with pytest I get the following error:

(env) @.*** cairo-contracts % pytest ========================================================= test session starts ========================================================= platform darwin -- Python 3.8.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 rootdir: /Users/user/dev/cairo-contracts plugins: web3-5.24.0, hypothesis-6.24.0, eth-brownie-1.17.1, xdist-1.34.0, forked-1.3.0 collected 0 items / 5 errors

=============================================================== ERRORS ================================================================ _ ERROR collecting tests/test_Account.py __ ImportError while importing test module '/Users/user/dev/cairo-contracts/tests/test_Account.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: ../../.pyenv/versions/3.8.7/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_Account.py:3: in from starkware.starknet.testing.starknet import Starknet E ModuleNotFoundError: No module named 'starkware'

shouldn't nile install take care of the dependencies?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OpenZeppelin/cairo-contracts/issues/93, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM77F2DQI4IBA7LMMGPP7DUOTW3XANCNFSM5JCE2XDQ .

poolpitako commented 2 years ago

Did you run nile init or nile install?

yes

poolpitako commented 2 years ago

OK, I found the problem.

% which pytest
/Users/user/.pyenv/shims/pytest

a surprise since my PATH starts with: /Users/user/dev/cairo-contracts/env/bin

Using the full path fixes the problem, basically: /Users/user/dev/cairo-contracts/env/bin/pytest or a shorter version: python -m pytest

martriay commented 2 years ago

how did you activate the virtual env?

poolpitako commented 2 years ago

how did you activate the virtual env?

great point. I just re-run source env/bin/activate and it worked. I guess the issue is that after nile install the env should be activated again 🤷

martriay commented 2 years ago

No, it should not be activated again. nile install has to be run within it in the first place.

poolpitako commented 2 years ago

No, it should not be activated again. nile install has to be run within it in the first place.

that's how I run it. env was activated when nile install was run. mac user with pyenv installed if you want to repro.

martriay commented 2 years ago

Mac user too, cannot reproduce :(

Are you able to reproduce it?

poolpitako commented 2 years ago

Mac user too, cannot reproduce :(

Are you able to reproduce it?

Env started working fine after the second source env/bin/activate and I haven't had the issue again. It's fine, let's move on :)