Open Miamoto-Musashi opened 3 years ago
Hi @Miamoto-Musashi
Please use python -m pytest
to run the tests instead of pipenv run pytest
Alternatively you need to set PYTHONPATH
environment variable to include the project directory. You can do so by running export PYTHONPATH=${PYTHONPATH}:${PWD}
in the project directory.
@Miamoto-Musashi You need to append the path of your app.py
` import json import os from http import HTTPStatus
import pytest from chalice.config import Config from chalice.local import LocalGateway
import sys sys.path.append("app.py PATH HERE") import app
@pytest.fixture def api(): return LocalGateway(app.app,Config())
def test_get_hello_world(api): response = api.handle_request(method='GET', path='/', headers={}, body=None) print(response) assert response['statusCode'] == HTTPStatus.OK response = json.loads(response['body']) assert response['hello'] == 'world' `
We need to do this because in the sample code, the test script is located inside the test folder and we are trying to import app.py which is located in the parent directory.
Hi, seems is not working for me, any hint?