Python 为什么在运行连接测试时发生ModuleNotFoundError
我在用python测试一个招摇过市的应用程序时遇到了问题。返回的错误为:ModuleNotFoundError:没有名为“routes.dataservices”的模块 我看到了一个我提到的,但仍然不工作。我看到的唯一区别是,我当前的python代码放在一个名为routes的文件夹中 招摇过市.ymlPython 为什么在运行连接测试时发生ModuleNotFoundError,python,flask,swagger,Python,Flask,Swagger,我在用python测试一个招摇过市的应用程序时遇到了问题。返回的错误为:ModuleNotFoundError:没有名为“routes.dataservices”的模块 我看到了一个我提到的,但仍然不工作。我看到的唯一区别是,我当前的python代码放在一个名为routes的文件夹中 招摇过市.yml paths: /leaderboard: get: tags: - Data Services summary: Get leaderboard
paths:
/leaderboard:
get:
tags:
- Data Services
summary: Get leaderboard
operationId: routes.dataservices.get_leaderboard
responses:
200:
description: Successful
content:
application/json:
schema:
$ref: '#/components/schemas/LeaderList'
400:
description: Retrieval error
content: {}
dataservices.py
def get_leaderboard():
return {'msg': 'ok'}, 200
import pytest
import connexion
flask_app = connexion.FlaskApp(__name__, specification_dir='../specs/')
flask_app.add_api('swagger.yml')
@pytest.fixture(scope='module')
def client():
with flask_app.app.test_client() as c:
yield c
def test_ui(client):
response = client.get('/v0.1/ui')
assert response.status_code == 308
测试api.py
def get_leaderboard():
return {'msg': 'ok'}, 200
import pytest
import connexion
flask_app = connexion.FlaskApp(__name__, specification_dir='../specs/')
flask_app.add_api('swagger.yml')
@pytest.fixture(scope='module')
def client():
with flask_app.app.test_client() as c:
yield c
def test_ui(client):
response = client.get('/v0.1/ui')
assert response.status_code == 308
目录结构
├── main
│ └── routes
│ └── dataservices.py
│ └── specs
│ └── swagger.yml
│ └── tests
│ └── test-api.py
您是否在您的
路由
文件夹中添加了\uuuuu init\uuuuuuuuuuuuuuuuuuuuuuupy
文件?我刚刚从routes.dataservices import*添加了文件和内容->但错误仍然保持:modulenofounderror:没有名为“routes.dataservices”的模块您是否在路由
文件夹中添加了\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu内容->从routes.dataservices导入*,但错误仍然保持:ModuleNotFoundError:没有名为“routes.dataservices”的模块