代码之家  ›  专栏  ›  技术社区  ›  NVS

在quart中运行pytest时禁用前_服务功能

  •  0
  • NVS  · 技术社区  · 4 年前

    我在我的before_service(app_initialization)函数中调用一个服务,我不想在pytests中调用它。实际上,我想禁用我的before_服务函数或类似的模拟功能。

    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
    

    @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
    
    0 回复  |  直到 4 年前
        1
  •  1
  •   pgjones    4 年前

    您的设备将在使用之前运行启动函数 test_app ,

    async with app.test_app() as 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
        return app
    
    推荐文章