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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: