Recall & Review
beginner
What is a test fixture in pytest?
A test fixture is a setup function that prepares the environment for tests. It can create objects, set states, or provide resources needed by tests.
Click to reveal answer
beginner
How do you define a fixture in pytest?
You define a fixture by creating a function and decorating it with
@pytest.fixture. This function can then be used by tests by adding its name as a parameter.Click to reveal answer
intermediate
Why use fixtures in Flask testing with pytest?
Fixtures help create a clean and reusable setup for Flask app, test client, and database. This keeps tests simple and avoids repeating setup code.
Click to reveal answer
intermediate
What does the
scope parameter in a pytest fixture control?The
scope controls how often the fixture is invoked. For example, function runs before each test, module runs once per file, and session runs once per test session.Click to reveal answer
intermediate
How can you use a Flask test client fixture in pytest?
Create a fixture that initializes the Flask app and returns
app.test_client(). Tests can then use this client to simulate HTTP requests to the app.Click to reveal answer
What decorator is used to create a fixture in pytest?
✗ Incorrect
The correct decorator to define a fixture in pytest is
@pytest.fixture.In Flask testing, what does the test client fixture provide?
✗ Incorrect
The Flask test client lets tests send HTTP requests to the app without running a server.
What does setting
scope='module' in a fixture do?✗ Incorrect
Scope 'module' means the fixture runs once for all tests in a single file.
How do tests access a fixture's return value?
✗ Incorrect
Tests receive fixture values by naming the fixture as a parameter in the test function.
Why are fixtures preferred over setup code inside tests?
✗ Incorrect
Fixtures help avoid repeating setup code and keep tests clean and organized.
Explain how to create and use a pytest fixture for a Flask test client.
Think about how to prepare the Flask app and provide a client for tests.
You got /4 concepts.
Describe the benefits of using test fixtures in pytest when testing Flask applications.
Consider how fixtures help organize and simplify test preparation.
You got /4 concepts.