nerdexam
Cisco

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…

Software Development and Design

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)
  • A
    76% (22)
  • B
    7% (2)
  • C
    3% (1)
  • D
    14% (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

#Python#Function testing#Unit testing basics#Conditional statements

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice