Challenge - 5 Problems
PyTest Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Key feature that makes PyTest popular
Which feature of PyTest most contributes to its popularity among Python developers?
Attempts:
2 left
💡 Hint
Think about how easy it is to write tests quickly with PyTest.
✗ Incorrect
PyTest allows writing simple test functions without extra setup, making tests easy and fast to write.
❓ Predict Output
intermediate2:00remaining
Output of a simple PyTest test function
What will be the result when running this PyTest test function?
PyTest
def test_sum(): assert sum([1, 2, 3]) == 6
Attempts:
2 left
💡 Hint
Check the sum of the list [1, 2, 3].
✗ Incorrect
The sum of [1, 2, 3] is 6, so the assertion passes and the test succeeds.
❓ assertion
advanced2:00remaining
Correct assertion to check exception in PyTest
Which PyTest assertion correctly checks that a ValueError is raised when calling int('abc')?
PyTest
import pytest def test_int_conversion(): # Fill in the assertion here pass
Attempts:
2 left
💡 Hint
PyTest uses a context manager to check exceptions.
✗ Incorrect
PyTest's raises context manager is the standard way to assert exceptions.
🔧 Debug
advanced2:00remaining
Identify the error in this PyTest test
What error will PyTest report when running this test code?
PyTest
def test_divide(): result = 10 / 0 assert result == 0
Attempts:
2 left
💡 Hint
What happens when dividing by zero in Python?
✗ Incorrect
Dividing by zero raises a ZeroDivisionError before the assertion runs.
❓ framework
expert3:00remaining
PyTest fixture scope behavior
Given a fixture with scope='module', how many times will it run if 3 test functions in the same module use it?
PyTest
import pytest @pytest.fixture(scope='module') def resource(): print('Setup resource') yield print('Teardown resource') def test_one(resource): pass def test_two(resource): pass def test_three(resource): pass
Attempts:
2 left
💡 Hint
Module scope means the fixture runs once per module.
✗ Incorrect
Fixtures with scope='module' run once before any tests in the module and teardown after all tests finish.