ethereum / populus

The Ethereum development framework with the most cute animal pictures
http://populus.readthedocs.org/
321 stars 321 forks source link

fixture 'chain' not found when running tests on fresh instance #479

Closed rbval closed 6 years ago

rbval commented 6 years ago

What was wrong?

py.test tests/ step doesn't work with a fresh env.

Setup

mkdir populus-test
cd populus-test
virtualenv -p python3 venv
source venv/bin/activate
pip install -e git+https://github.com/ethereum/populus#egg=populus
cp venv/src/populus/populus/assets/defaults.v9.config.json ./project.json

Last step was suggested by @voith in https://github.com/ethereum/populus/issues/450

Run

populus init
populus compile
py.test tests/

Output

================================================ test session starts =================================================
platform darwin -- Python 2.7.15, pytest-3.8.1, py-1.6.0, pluggy-0.7.1
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('.../populus-test/.hypothesis/examples')
rootdir: .../populus-test, inifile:
plugins: xdist-1.18.1, hypothesis-3.73.3
collected 2 items
tests/test_greeter.py EE                                                                                       [100%]

======================================================= ERRORS =======================================================
___________________________________________ ERROR at setup of test_greeter ___________________________________________
file .../populus-test/tests/test_greeter.py, line 1
  def test_greeter(chain):
E       fixture 'chain' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory, worker_id
>       use 'pytest --fixtures [testpath]' for help on them.

.../populus-test/tests/test_greeter.py:1
_______________________________________ ERROR at setup of test_custom_greeting _______________________________________
file .../populus-test/tests/test_greeter.py, line 8
  def test_custom_greeting(chain):
E       fixture 'chain' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory, worker_id
>       use 'pytest --fixtures [testpath]' for help on them.

.../populus-test/tests/test_greeter.py:8
============================================== 2 error in 0.02 seconds ===============================================

Cute Animal Picture

image

voith commented 6 years ago

@rbval I was getting the same error. My problem was that pytest was not installed in the same virtualenv. what does which py.test say for you?

voith commented 6 years ago

Populus Version: -e git+https://github.com/ethereum/populus#egg=populus (fresh install throws the force_text error

If you install from current master then this issue should be resolved.

rbval commented 6 years ago

@voith which py.test gives me /usr/local/bin/py.test

Going for pip install py.test in the virtualenv throws the following error: ValueError: please use 'pytest' pypi package instead of 'py.test'

However if I do: pip install pytest it gives Requirement already satisfied to everything. How did you solve this in the virtualenv @voith ?

voith commented 6 years ago

/usr/local/bin/py.test

You're facing the same problem that I was facing. It tells you that pytest is being picked from your global path.

pip install py.test

the . in pytest is not longer needed. pip install pytest will do.

Also, I had to deactivate and re-active the virtualenv to make sure that it is picking pytest from the correct path (virtualenv).

Closing this as it is not a bug in populus, but feel free to continue the discussion.

rbval commented 6 years ago

Alright, the activate + deactivate seemed to work, weird. How would that be handle in a Dockerfile for example?