Last active
October 13, 2020 16:37
-
-
Save sportebois/b73058381be132297523a31a0896c760 to your computer and use it in GitHub Desktop.
Common pytest fixture to use Flask test client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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