Recall & Review
beginner
What does the
is operator check in Python?The
is operator checks if two variables point to the exact same object in memory, not just if they have the same value.Click to reveal answer
beginner
How is
is not different from != in Python?is not checks if two variables are not the same object (different identity), while != checks if their values are different.Click to reveal answer
beginner
In pytest, how do you assert that two variables are the same object?
Use
assert a is b to check that a and b refer to the same object in memory.Click to reveal answer
intermediate
Why might
is be preferred over == in some tests?Because
is confirms the exact object identity, which is important when you want to ensure no copies or different instances are involved.Click to reveal answer
beginner
What will this pytest assertion check? <br>
assert a is not b
It checks that
a and b are not the same object in memory. They can have the same value but must be different objects.Click to reveal answer
What does
assert a is b verify in pytest?✗ Incorrect
is checks object identity, so the assertion verifies a and b refer to the same object.Which operator checks if two variables do NOT refer to the same object?
✗ Incorrect
is not checks that two variables are not the same object in memory.If
a == b is True but a is b is False, what does it mean?✗ Incorrect
Equality means same value, but identity means same object. Here, values match but objects differ.
Which pytest assertion checks that two variables are NOT the same object?
✗ Incorrect
assert a is not b confirms a and b are different objects.Why is using
is important when testing singleton objects like None?✗ Incorrect
Singletons like None have only one instance, so
is confirms the exact object is used.Explain the difference between
is and == in Python testing.Think about whether you want to check if two things are exactly the same object or just look the same.
You got /4 concepts.
Describe how to write a pytest assertion to verify two variables are not the same object.
Focus on the keyword that means 'not the same object'.
You got /3 concepts.