我遵循了how to contribute to Flask教程。
当我运行pytest tests/*.py
时,测试通过,但当我只运行pytest
时(如上面的参考文献中所述),我收到此错误消息:
pytest
============================= test session starts ==============================
platform linux -- Python 3.5.2, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /home/begueradj/flask, inifile: setup.cfg
collected 377 items / 3 errors
==================================== ERRORS ====================================
____________ ERROR collecting examples/flaskr/tests/test_flaskr.py _____________
ImportError while importing test module '/home/begueradj/flask/examples/flaskr/tests/test_flaskr.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
examples/flaskr/tests/test_flaskr.py:15: in <module>
from flaskr import flaskr
E ImportError: No module named 'flaskr'
__________ ERROR collecting examples/minitwit/tests/test_minitwit.py ___________
ImportError while importing test module '/home/begueradj/flask/examples/minitwit/tests/test_minitwit.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
examples/minitwit/tests/test_minitwit.py:14: in <module>
from minitwit import minitwit
E ImportError: No module named 'minitwit'
_____ ERROR collecting examples/patterns/largerapp/tests/test_largerapp.py _____
ImportError while importing test module '/home/begueradj/flask/examples/patterns/largerapp/tests/test_largerapp.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
examples/patterns/largerapp/tests/test_largerapp.py:1: in <module>
from yourapplication import app
E ImportError: No module named 'yourapplication'
!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 3 error in 2.78 seconds ============================
我的环境是:
为什么会发生这种情况以及如何解决?
答案 0 :(得分:2)
现在Flask 1.0已经出局,仅pytest
将仅运行tests
目录中的测试。安装示例后,使用pytest tests examples
对两者进行测试。
pip install -e examples/tutorial
pip install -e examples/javascript
pytest tests examples
贡献文档 已过期,您需要运行pytest tests
。如果你想测试这些例子(这就是现在失败了),你需要像tox
那样安装它们。
pip install -e examples/flaskr
pip install -e examples/minitwit
pip install -e examples/patterns/largerapp
pytest
或者,运行tox -e py
运行整个测试套件,或运行tox
以在所有受支持的Python版本上运行套件。