Testing Questions and Answers

Take Exam

Python Programming - Testing Questions with Answers introduce concepts of verifying code reliability using unit tests. These Python Testing Questions are essential for Infosys, Accenture, and Capgemini exams to evaluate coding accuracy and debugging skills

Testing

Showing 10 of 25 questions

11. What does the command pytest -v do?

  • A) Runs pytest in visual mode
  • B) Displays detailed output for each test case
  • C) Deletes previous test results
  • D) Installs pytest
Show Answer Report

12. What is the output if all assert statements pass in a test file?

  • A) Failure message
  • B) Error traceback
  • C) Success message
  • D) No output
Show Answer Report

13. What does assertTrue() in unittest check?

  • A) If the value is False
  • B) If the value is None
  • C) If the expression is True
  • D) If the value is zero
Show Answer Report

14. Which method is used to perform cleanup after each test in unittest?

  • A) tearDown()
  • B) afterTest()
  • C) cleanUp()
  • D) removeTest()
Show Answer Report

15. What is the default behavior when an assert fails in pytest?

  • A) Test skips automatically
  • B) Exception is ignored
  • C) Test fails and stops at that point
  • D) System restarts
Show Answer Report

16. What is mock used for in testing?

  • A) To decorate functions
  • B) To simulate objects or behavior
  • C) To compile code faster
  • D) To hide test results
Show Answer Report

17. When using pytest.raises, you generally test for what?

  • A) returned value correctness
  • B) time efficiency
  • C) expected exceptions
  • D) output formatting
Show Answer Report

18. What is the output of assert "a" in "apple"?

  • A) AssertionError
  • B) True
  • C) False
  • D) ValueError
Show Answer Report

19. Which command runs all tests in the current directory using pytest?

  • A) pytest .
  • B) python run_tests
  • C) pytest all
  • D) python -m unittest
Show Answer Report

20. What is test coverage in testing?

  • A) Number of test files
  • B) Portion of code executed during testing
  • C) Compilation speed
  • D) Function name length
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test