200-901 · Question #17
A function my_func() returns True when it executes normally. Which Python snippet tests my_func()? A. B. C. D.
The correct answer is A. def test_func(self): self.assertTrue(my_func()). The function returns True, so the test should assert that the return value is True using self.assertTrue(my_func()). Option B uses assertFalse, which would fail because the function returns True. Option C uses assertEqual with a string '{{true}}' which is not a valid boolean…
Question
A function my_func() returns True when it executes normally. Which Python snippet tests my_func()? A. B. C. D.
Options
- Adef test_func(self): self.assertTrue(my_func())
- Bdef test_func(self): self.assertFalse(my_func())
- Cdef test_func(self): self.assertEqual(my_func, '{true}')
- Ddef test_func(self): self.assertRaises(my_func())
How the community answered
(29 responses)- A76% (22)
- B7% (2)
- C3% (1)
- D14% (4)
Explanation
The function returns True, so the test should assert that the return value is True using self.assertTrue(my_func()). Option B uses assertFalse, which would fail because the function returns True. Option C uses assertEqual with a string '{{true}}' which is not a valid boolean comparison. Option D uses assertRaises, which is used to test that an exception is raised, not a return value.
Topics
Community Discussion
No community discussion yet for this question.