Home > Blockchain >  How test_client in Flask App Testing sets the url and how it works in the backend?
How test_client in Flask App Testing sets the url and how it works in the backend?

Time:10-14

So I was trying to automate my flask app api's and was closely following few docs./blogs written by Patrick Kennedy and was able to do so but have few doubts related to requests module and test_client(Werkzeug test Client)

My approach :

Have created a fixture where in I have imported my app with test client and pushing the context and using it I am able to hit the api's defined in my app.py. So to do get using one of the api's, I m doing this :

response = test_client.get(url) #url without http://hostname:port and it works fine, without any issues.

While if I want to use requests module provided by python, I need to provide the whole url i.e. with http://hostname:port

So my question is, how test_client manages this???

If I am using test_client, will it be a correct approach to have a url without hostname and port?? (even though I am getting the expected output)

CodePudding user response:

Flask is using WerkZeug's Test Client:

https://werkzeug.palletsprojects.com/en/2.0.x/test/#werkzeug.test.Client

This client wraps your application instance and therefore does not need to know the absolute path to your application.

  • Related