0
0
PyTesttesting~20 mins

Test functions in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Test Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple pytest test function
What is the test result when running this pytest test function?
PyTest
def test_sum():
    assert 2 + 3 == 5
ASyntaxError due to missing colon
BTest fails with AssertionError
CTest passes with no errors
DTypeError because of wrong assertion
Attempts:
2 left
💡 Hint
Check if the assertion condition is true.
assertion
intermediate
2:00remaining
Identify the failing assertion in pytest
Which assertion will cause the pytest test to fail?
PyTest
def test_values():
    assert 10 > 5
    assert 'a' == 'b'
    assert [1, 2] == [1, 2]
Aassert 'a' == 'b'
Bassert [1, 2] == [1, 2]
Cassert 10 > 5
DAll assertions pass
Attempts:
2 left
💡 Hint
Check which condition is false.
🔧 Debug
advanced
2:00remaining
Find the error in this pytest test function
What error will pytest report when running this test function?
PyTest
def test_division():
    result = 10 / 0
    assert result == 0
AZeroDivisionError at runtime
BTest passes successfully
CSyntaxError due to missing colon
DAssertionError because result is not 0
Attempts:
2 left
💡 Hint
Consider what happens when dividing by zero in Python.
framework
advanced
2:00remaining
pytest test discovery rules
Which function name will pytest automatically discover as a test?
Adef example_test():
Bdef test_example():
Cdef check_test():
Ddef example():
Attempts:
2 left
💡 Hint
pytest looks for functions starting with a specific prefix.
🧠 Conceptual
expert
2:00remaining
Effect of multiple assertions in one pytest test function
What happens when multiple assertions exist in one pytest test function and the first assertion fails?
Apytest retries the test automatically on failure
BAll assertions run; all failures are reported together
CTest passes if any assertion passes
DTest stops at first failed assertion; later assertions are not checked
Attempts:
2 left
💡 Hint
Think about how Python handles exceptions during test execution.