Challenge - 5 Problems
Grouping Guru
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of grouped pytest tests with fixtures
Consider the following pytest code with a fixture and two test functions grouped in a class. What will be the output when running pytest on this file?
PyTest
import pytest @pytest.fixture def setup_data(): return [1, 2, 3] class TestGroup: def test_sum(self, setup_data): assert sum(setup_data) == 6 def test_len(self, setup_data): assert len(setup_data) == 3
Attempts:
2 left
💡 Hint
Think about what the fixture returns and the assertions in each test.
✗ Incorrect
The fixture 'setup_data' returns a list [1, 2, 3]. The sum is 6 and length is 3, so both assertions are true and tests pass.
❓ assertion
intermediate1:30remaining
Correct assertion to check all items in a grouped test
You have a grouped test that checks if all items in a list are positive. Which assertion correctly verifies this in pytest?
PyTest
def test_all_positive(): data = [5, 10, 15] # Which assertion is correct here?
Attempts:
2 left
💡 Hint
Think about checking every item, not just some or the sum.
✗ Incorrect
Using all() ensures every item is greater than zero, which matches the test goal.
🔧 Debug
advanced2:00remaining
Identify the cause of test skipping in grouped pytest tests
Given this pytest code, why is the test 'test_feature' skipped when running the group?
PyTest
import pytest @pytest.mark.skipif(True, reason="Feature not ready") class TestFeatures: def test_feature(self): assert True
Attempts:
2 left
💡 Hint
Look at the decorator and its condition.
✗ Incorrect
The @pytest.mark.skipif(True) on the class causes pytest to skip all tests inside unconditionally.
❓ framework
advanced2:30remaining
Best practice for grouping tests in pytest
Which of the following is the best practice to group related tests in pytest for better organization and reuse?
Attempts:
2 left
💡 Hint
Think about pytest conventions and fixture usage.
✗ Incorrect
Pytest recommends grouping tests in classes without __init__ and using fixtures for setup to keep tests isolated and organized.
🧠 Conceptual
expert3:00remaining
Effect of test grouping on test discovery and execution order in pytest
In pytest, how does grouping tests inside classes affect test discovery and execution order compared to standalone test functions?
Attempts:
2 left
💡 Hint
Consider how pytest collects and orders tests.
✗ Incorrect
Pytest discovers tests in file order. Tests inside classes run in the order they appear in the class, preserving grouping order.