简体   繁体   English

Flask:使用 pytest 夹具注入“client”参数

[英]Flask: injection of the "client" parameter using pytest fixture

I just can't figure out how pytest determines the parameter "client" in the Flask test suite located in this file .我只是无法弄清楚 pytest 如何确定位于此文件中的 Flask 测试套件中的参数“client”。

class SwaggerTest(object):
    def test_specs_endpoint(self, api, client):
        data = client.get_specs("")
        assert data["swagger"] == "2.0"
        assert data["basePath"] == "/"
        assert data["produces"] == ["application/json"]
        assert data["consumes"] == ["application/json"]
        assert data["paths"] == {}
        assert "info" in data

I've looked in the conftest.py file in the same directory but there is no definition of a fixture for "client".我查看了同一目录中的 conftest.py 文件,但没有定义“客户端”的夹具。

Thanks for your help.谢谢你的帮助。

When I see a fixture being used my immediate reaction like you, is to check the conftest.py file.当我看到一个正在使用的夹具时,我和你一样的第一反应是检查conftest.py文件。 Since it is not defined there, my next thought is to check the testing requirements which leads me to this line .由于那里没有定义,我的下一个想法是检查导致我进入这一行的测试要求。 After finding the documentation for pytest-flask we can see that this fixture, client , is defined as a fixture within that library.在找到pytest-flask的文档后,我们可以看到这个夹具client被定义为该库中的夹具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM