Skip to content

Instantly share code, notes, and snippets.

@sportebois
Last active October 13, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sportebois/b73058381be132297523a31a0896c760 to your computer and use it in GitHub Desktop.
Save sportebois/b73058381be132297523a31a0896c760 to your computer and use it in GitHub Desktop.
Common pytest fixture to use Flask test client
@pytest.fixture
def client():
my_project.app.config['TESTING'] = True
with my_project.app.test_client() as client:
with my_project.app.app_context():
# Do some initialization stuff
yield client
# Or
@pytest.fixture
def test_client():
configure_app(flask_app, config_name=Environments.TESTS)
# I use this a lot for custom Test client classes to inject custom things
my_project.app.test_client_class = CustomApiTestClient
client = my_project.app.
yield client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment