Recall & Review
beginner
What does the
in keyword check in a pytest assertion?The
in keyword checks if a value or element exists inside a container like a list, string, or dictionary keys.Click to reveal answer
beginner
How do you assert that an item is NOT in a list using pytest?
Use
assert item not in list to check the item is absent from the list.Click to reveal answer
beginner
Example: <br>
assert 'apple' in fruits <br> What happens if 'apple' is not in fruits?The test will fail and pytest will show an AssertionError because the condition is false.
Click to reveal answer
intermediate
Why is checking membership useful in software testing?
It helps verify if expected data or elements appear in outputs, lists, or responses, ensuring correct program behavior.
Click to reveal answer
beginner
What types of containers can you check membership in with
in and not in?You can check membership in lists, tuples, sets, strings, and dictionary keys.
Click to reveal answer
What does
assert 'cat' in animals check?✗ Incorrect
The assertion checks if 'cat' exists inside the animals container.
How do you assert that 'dog' is NOT in the list pets?
✗ Incorrect
Use 'assert 'dog' not in pets' to check absence.
Which container membership does
in NOT check?✗ Incorrect
Membership checks require containers; integers are not containers.
If
assert 'x' in 'xyz' fails, what does it mean?✗ Incorrect
If the assertion fails, 'x' is not found in 'xyz'.
What error does pytest show if a membership assertion fails?
✗ Incorrect
Failed assertions raise AssertionError in pytest.
Explain how to use
in and not in in pytest assertions with examples.Think about checking if an item exists or does not exist in a list or string.
You got /4 concepts.
Why is checking membership important in software testing? Give a simple scenario.
Consider how you confirm something is included or excluded in a result.
You got /3 concepts.