0
0
Flaskframework~10 mins

Test fixtures with pytest in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the pytest module.

Flask
import [1]
Drag options to blanks, or click blank then click option'
Aflask
Bunittest
Cpytest
Drequests
Attempts:
3 left
💡 Hint
Common Mistakes
Importing flask instead of pytest
Using unittest which is a different testing framework
2fill in blank
medium

Complete the code to define a pytest fixture that creates a Flask app instance.

Flask
@pytest.fixture
def app():
    app = Flask(__name__)
    app.config['TESTING'] = [1]
    return app
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting TESTING to False disables testing features
Using None or 0 instead of True
3fill in blank
hard

Fix the error in the test function to use the fixture correctly.

Flask
def test_home([1]):
    response = app.test_client().get('/')
    assert response.status_code == 200
Drag options to blanks, or click blank then click option'
Aapp
Brequest
Cfixture
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the fixture
Not passing any parameter to the test function
4fill in blank
hard

Fill both blanks to create a fixture that provides a test client from the Flask app fixture.

Flask
@pytest.fixture
def client([1]):
    return [2].test_client()
Drag options to blanks, or click blank then click option'
Aapp
Bclient
Crequest
Dflask_app
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong fixture name as parameter
Returning something other than the test client
5fill in blank
hard

Fill all three blanks to write a test using the client fixture to check the home page response.

Flask
def test_home_page([1]):
    response = [2].get('/')
    assert response.[3] == 200
Drag options to blanks, or click blank then click option'
Aclient
Cstatus_code
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using app instead of client in the test function
Checking a wrong attribute instead of status_code