我試圖盡早將測驗引入 Python 3.9 專案,但是我在使用 pytest 時遇到了麻煩。
test_legacy.py:
from crmpicco.subtasks.legacy import Legacy
def test_is_complete(self):
legacy = Legacy()
assert legacy.is_complete(self) == True
我試圖測驗的課程是legacy.py:
from crmpicco.subtasks.subtask import Subtask
class Legacy(Subtask):
def execute(self):
print("legacy")
def is_complete(self):
return True
當我運行這個時,我得到:
匯入測驗模塊“/private/var/www/crmpicco/crmpicco/tests/test_legacy.py”時出現匯入錯誤。提示:確保您的測驗模塊/包具有有效的 Python 名稱。
E ModuleNotFoundError: 沒有名為“crmpicco”的模塊
我曾嘗試向__init__.py我的/tests目錄中添加一個檔案,然后再次將其洗掉,但沒有效果
我錯過了什么?
uj5u.com熱心網友回復:
pytest 試圖找到 rootdir并且可能是它的東西/private/var/www/crmpicco/crmpicco
最簡單的方法是運行測驗python -m pytestwhich run pytestbut added 。到PYTHONPATH
uj5u.com熱心網友回復:
為我解決這個問題的是向PYTHONPATH我的外殼添加匯出。
export PYTHONPATH=/var/www/crmpicco/crmpicco
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/360822.html
標籤:Python 蟒蛇-3.x 单元测试 测试 pytest
