py.test
आदेश, मेरे मामले में विफल हो रहा है जबकि pytest
पूरी तरह से ठीक चल रहा है।"py.test" "pytest" कमांड
मैं pytest-कुप्पी प्लगइन का उपयोग:
platform linux -- Python 3.5.2, pytest-3.0.2, py-1.4.31, pluggy-0.3.1
rootdir: /home/sebastian/develop/py/flask-rest-template, inifile:
plugins: flask-0.10.0
जब मैं आह्वान $ py.test
मैं निम्नलिखित त्रुटि मिलती है:
import pytest
from app.app import create_app
@pytest.fixture
def app():
app = create_app()
return app
:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/_pytest/config.py", line 301, in _getconftestmodules
return self._path2confmods[path]
KeyError: local('/home/sebastian/develop/py/flask-rest-template')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/_pytest/config.py", line 332, in _importconftest
return self._conftestpath2mod[conftestpath]
KeyError: local('/home/sebastian/develop/py/flask-rest-template/conftest.py')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/_pytest/config.py", line 338, in _importconftest
mod = conftestpath.pyimport()
File "/usr/local/lib/python3.5/dist-packages/py/_path/local.py", line 650, in pyimport
__import__(modname)
File "/usr/local/lib/python3.5/dist-packages/_pytest/assertion/rewrite.py", line 207, in load_module
py.builtin.exec_(co, mod.__dict__)
File "/home/sebastian/develop/py/flask-rest-template/conftest.py", line 2, in <module>
from app.app import create_app
File "/home/sebastian/develop/py/flask-rest-template/app/app.py", line 1, in <module>
from flask import Flask
ImportError: No module named 'flask'
ERROR: could not load /home/sebastian/develop/py/flask-rest-template/conftest.py
यह मेरा वास्तविक conftest.py
फ़ाइल है मेरी परियोजना संरचना इस तरह है:
.
├── app
│ ├── __init__.py
│ ├── app.py
│ └── config.py # flask configuration objects
├── conftest.py # pytest configruation
├── requirements.txt
├── ...
└── tests
└── ...
तो, दो आदेशों के बीच क्या अंतर है? और क्यों एक असफल रहा है और दूसरा नहीं?
अद्यतन 1
1) मैं python3 -m app.app
3) अब pytest
और साथ from app.config import Config
2) चल रहा है कुप्पी की तरह निरपेक्ष लोगों के लिए अपने रिश्तेदार के आयात from .config import Config
या from config import Config
बदलना पड़ा py.test
काम सामान्य
आपकी मदद के लिए बहुत बहुत धन्यवाद, दोस्तों!
अपडेट 2
यह अजीब ... उम्मीद हो रही है जब पूर्ण आयात, चल अजगर का उपयोग कर -m
विकल्प और debug=True
तो werkzeug
पुस्तकालय स्रोतों को पुन: लोड नहीं कर रहा है के साथ कुप्पी के साथ के रूप में:
http://chase-seibert.github.io/blog/2015/06/12/flask-werkzeug-reloader-python-dash-m.html
https://github.com/pallets/werkzeug/issues/461
https://github.com/pallets/flask/issues/1246
इससे मुझे अपने app/app.py
में मदद की:
if __name__ == '__main__':
app.run(debug=True, use_reloader=False)
फिर python -m app.app
ठीक काम करता है।
'pytest' आदेश [नई] (https://github.com/pytest-dev/pytest/issues/1629) तरीका है, और आप की संभावना pytest के एक पुराने संस्करण के आसपास फांसी की है। – wim
संकेत के लिए धन्यवाद! तो मैं भविष्य में केवल 'pytest' का उपयोग करूंगा ... – swiesend
' कौन सा pytest' और 'py.test' क्या कहता है? –