🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Testing Python Code: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What happens when assert x 0, "x must be positive" runs with x = -2?
  2. Q2. Why should you not use assert to validate user input in a real program?
  3. Q3. In unittest, which methods of a TestCase class are run as tests?
  4. Q4. What is setUp used for?
  5. Q5. What does this print? (code)
  6. Q6. A function gives free delivery for orders of Rs 500 or more. Which set of test inputs is best?
  7. Q7. What does @pytest.mark.parametrize do?
  8. Q8. doctest.testmod() returns TestResults(failed=0, attempted=3). What does this mean?
  9. Q9. In TDD, what is the first step of the cycle?
  10. Q10. How should you compare two float results in a unittest test?