不知道这是否与google-cloud相关或与pytest相关。查看下面的文件。
当我运行python app/my_script.py
或python -m app.my_script
时,脚本运行良好。
但是当我运行pytest
时,脚本from google.cloud import vision
中的行将引发“ ModuleNotFoundError:没有名为'google.cloud'的模块”。
我尝试将各种软件包名称添加到requirements.txt文件中并/或运行带有pip install google-cloud
标志和不带有pip install google-cloud-language
标志的--upgrade
和google-cloud-vision
均未成功。我可以采取哪些步骤来克服此错误?
conftest.py :(空)
requirements.txt:
from google.cloud import vision
from google.cloud.vision import types
def new_client():
client = vision.ImageAnnotatorClient()
return client
if __name__ == "__main__":
client = new_client()
# etc...
app / my_script.py:
from app.my_script import new_client
# tests here...
test / test_my_script.py:
largest = None
smallest = None
while True:
num = input("Enter number:")
if num == 'done':
break
try:
num = int(num)
except:
print("Invalid input")
if smallest is None or num < smallest:
smallest = num
if largest is None or largest > num:
largest = num
print("Maximum", largest)
print("Minimum", smallest)