Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest-api test: fix ping server step #997

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ jobs:

pytest-api:
runs-on: ubuntu-latest
env:
# Port for web container
# See docker-compose.yml
PORT: 8002
steps:
- uses: actions/checkout@v2
- name: Build & run docker
run: PORT=8002 docker-compose up -d --build
run: docker-compose up -d --build
- name: Ping server
run: curl http://localhost:8002/docs
run: wget --spider --tries=12 http://localhost:$PORT/docs
Comment on lines -26 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remind me the reason of this change? (not familiar with the spider option, the "tries" flag seems explicit)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spider does only an 'exist' check and avoid downloading anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frgfm Also, curl has an option --retry-all-errors to retry in any case but this option is only available in latest version of curl which can't be (easily) installed on Ubuntu 20.04. So it may still fail for various reasons that we can't catch. However, wget comes out of the box with a "retry on all errors".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frgfm Concerning your comment on version, it's a good remark. I didn't changed anything on my side and it didn't install the latest version of fastapi 🤔

- name: Install dependencies in docker
run: |
PORT=8002 docker-compose exec -T web python -m pip install --upgrade pip
PORT=8002 docker-compose exec -T web pip install -r requirements-dev.txt
docker-compose exec -T web python -m pip install --upgrade pip
docker-compose exec -T web pip install -r requirements-dev.txt
- name: Run docker test
run: PORT=8002 docker-compose exec -T web pytest .
run: docker-compose exec -T web pytest .
2 changes: 1 addition & 1 deletion api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fastapi>=0.65.2
fastapi>=0.73.0
uvicorn>=0.11.1
python-multipart==0.0.5
python-doctr>=0.2.0
8 changes: 4 additions & 4 deletions api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# This program is licensed under the Apache License version 2.
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.

import pytest
import pytest_asyncio
import requests
from httpx import AsyncClient

from app.main import app


@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
def mock_recognition_image(tmpdir_factory):
url = 'https://user-images.githubusercontent.com/76527547/117133599-c073fa00-ada4-11eb-831b-412de4d28341.jpeg'
return requests.get(url).content


@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
def mock_detection_image(tmpdir_factory):
url = 'https://user-images.githubusercontent.com/76527547/117319856-fc35bf00-ae8b-11eb-9b51-ca5aba673466.jpg'
return requests.get(url).content


@pytest.fixture(scope="function")
@pytest_asyncio.fixture(scope="function")
async def test_app_asyncio():
# for httpx>=20, follow_redirects=True (cf. https://github.com/encode/httpx/releases/tag/0.20.0)
async with AsyncClient(app=app, base_url="http://test") as ac:
Expand Down