为什么在运行连接测试时出现ModuleNotFoundError

时间:2020-02-12 08:40:15

标签: python flask swagger

我在用python测试swagger应用程序时遇到问题。返回的错误是:ModuleNotFoundError:没有名为“ routes.dataservices”的模块

我看到了我提到的post,但仍然无法正常工作。我看到的唯一区别是,我当前的python代码位于名为 routes 的文件夹中。

swagger.yml

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

test_api.py

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

0 个答案:

没有答案