1

I am having problem with testing of a swagger application in python. The error returned was: ModuleNotFoundError: No module named 'routes.dataservices'

I saw a post which I referred to but is still not working. The only difference I see is that my current python codes are placed in a folder called 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

Directory structure

├── main
│   └── routes
│       └── dataservices.py
│   └── specs
│       └── swagger.yml
│   └── tests
│       └── test-api.py
Eugene
  • 1,013
  • 1
  • 22
  • 43
  • Did you add an `__init__.py` in your `routes` folder ? – thomask Feb 12 '20 at 09:27
  • I just added the file and the content -> from routes.dataservices import * But the error still maintains: ModuleNotFoundError: No module named 'routes.dataservices' – Eugene Feb 13 '20 at 01:29

0 Answers0