Why Don’t You Need To Specify Ports in Flask Tests?
When you’re running a simple Flask app in development, you might specify a particular port where the server should run (the default is 5000).
Then in your browser you can visit localhost:5000/foobar
.
But in Flask tests you don’t need to specify the port, just the route:
from flask_testing import TestCase class TestFoobar(TestCase): def test_foobar(self): response = self.client.get("/foobar") # ...
That’s because, underneath, Werkzeug test clients don’t issue actual HTTP requests. They abstract that away.
Source: this Stack Overflow post.