Challenge - 5 Problems
Lazy Fixture Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest lazy fixture usage
What will be the output when running this pytest test with lazy_fixture?
PyTest
import pytest from pytest_lazyfixture import lazy_fixture @pytest.fixture def data(): return 5 @pytest.mark.parametrize('value', [lazy_fixture('data')]) def test_value(value): assert value == 5 print(f'Value is {value}')
Attempts:
2 left
💡 Hint
Remember lazy_fixture allows using fixtures inside parametrize.
✗ Incorrect
The lazy_fixture('data') injects the fixture value 5 into the parameter. The assertion passes and the print statement outputs 'Value is 5'.
❓ assertion
intermediate1:30remaining
Correct assertion with lazy_fixture parameter
Given this test using lazy_fixture, which assertion correctly verifies the parameter is a string 'hello'?
PyTest
import pytest from pytest_lazyfixture import lazy_fixture @pytest.fixture def greeting(): return 'hello' @pytest.mark.parametrize('msg', [lazy_fixture('greeting')]) def test_greeting(msg): # Which assertion is correct here?
Attempts:
2 left
💡 Hint
Use equality check for string values.
✗ Incorrect
Option C correctly asserts the string equality. Option C uses 'is' which is not reliable for string content comparison. Options A and D are incorrect.
🔧 Debug
advanced2:00remaining
Identify the error in lazy_fixture usage
What error will occur when running this test code?
PyTest
import pytest from pytest_lazyfixture import lazy_fixture @pytest.fixture def number(): return 10 @pytest.mark.parametrize('num', [lazy_fixture('num')]) def test_number(num): assert num == 10
Attempts:
2 left
💡 Hint
Check the fixture name passed to lazy_fixture matches defined fixture.
✗ Incorrect
The fixture defined is 'number' but lazy_fixture is called with 'num' which does not exist, causing FixtureLookupError.
❓ framework
advanced1:30remaining
Best practice for using lazy_fixture in pytest parametrize
Which option shows the best practice for using lazy_fixture in pytest parametrize to test multiple fixture values?
Attempts:
2 left
💡 Hint
Think about how to parametrize multiple fixture values cleanly.
✗ Incorrect
Option D correctly uses a list of lazy_fixture calls inside parametrize to test multiple fixture values in one test function.
🧠 Conceptual
expert1:30remaining
Why use lazy_fixture instead of direct fixture injection in parametrize?
What is the main reason to use lazy_fixture in pytest parametrize instead of directly passing fixture names?
Attempts:
2 left
💡 Hint
Think about how pytest parametrize works with fixtures.
✗ Incorrect
Pytest parametrize cannot directly use fixtures as parameters. lazy_fixture allows referencing fixtures lazily inside parametrize.