As I know performing a functional test is done with an app context. This-for I am using this modular fixture:
@pytest.fixture(scope='module')
def test_client():
flask_app = create_app("ENV_FILE_LOCATION")
# Create a test client using the Flask application configured for testing
with flask_app.test_client() as testing_client:
# Establish an application context
with flask_app.app_context():
yield testing_client # this is where the testing happens!
And I am after calling the test_client to do tests on each route, for example:
c = app.test_client()
response = c.get('/test/url')
# test response
When performing the tests on some routes the process works well. However, I have a one that is calling another route I get this error
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=5500): Max retries exceeded with url: /test/nested_route_call (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f56f3c30580>: Failed to establish a new connection: [Errno 111] Connection refused'))
It is logical since the app is not running and the call is performed to the closed app. When doing the tests while the app is running, all things goes rightly. However as I must incorporate my tests in a pre-build process, it must be closed, so is there any solution to fix the issue.