Skip to content

Idea: Run tests locally outside docker #65

Description

@skrchnavy

related also to #24.

At first, the tests/api/* are not using fixture server_api

from app.tests.utils.utils import get_server_api

def test_celery_worker_test(superuser_token_headers):
    server_api = get_server_api()

shall be

def test_celery_worker_test(server_api, superuser_token_headers):

this would allow to improve pytest tests this way (as idea, further improvements possible):

from multiprocessing import Process

import pytest
import uvicorn

def run_server():
    uvicorn.run("app.main:app", port=8123)

@pytest.fixture(scope="module")
def server_api(server):
    proc = Process(target=run_server, args=(), daemon=True)
    proc.start()
    # maybe some sleep here to wait for server starts
    yield ('localhost', 8123)
    proc.kill()  # Cleanup after test

credits to: https://stackoverflow.com/questions/57412825/how-to-start-a-uvicorn-fastapi-in-background-when-testing-with-pytest

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions