0

I am using Quart App.

I am calling a service in my before_serving(app_initionalization) function and I do not want to call that in pytests. Actually, I want to disable my before_serving function or something like mock it.

import pytest
@pytest.mark.asyncio
async def test_my_api_call(test_app: Pint, headers: dict):
    test_client = test_app.test_client()
    response = await test_client.get("/get_user", headers)
    assert response.status_code == 200

This is my test_app.

@pytest.fixture(name="test_app", scope="function")
async def _test_app(s3_client, tmp_path, async_mongodb):
    os.environ["BLOB_STORE"] = str(tmp_path)
    db_config['db'] = async_mongodb
    async with app.test_app() as test_app:
         yield test_app
NVS
  • 400
  • 3
  • 10
  • How is the test_app fixture defined? The before/after serving funcs are only called if the test_app method is used on the app, see https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html#testing – pgjones Dec 05 '21 at 16:05
  • I have updated the code with test_app fixture. I have gone through your all quart pages already. Please help here. – NVS Dec 05 '21 at 17:23

1 Answers1

1

Your fixture will run the before-serving startup functions as it uses the test_app,

async with app.test_app() as test_app:

As you don't wish to run these you can change your fixture to,

@pytest.fixture(name="test_app", scope="function")
async def _test_app(s3_client, tmp_path, async_mongodb):
    os.environ["BLOB_STORE"] = str(tmp_path)
    db_config['db'] = async_mongodb
    return app
pgjones
  • 6,044
  • 1
  • 14
  • 12