Testing Questions and Answers
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
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
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
14. Which method is used to perform cleanup after each test in unittest?
- A) tearDown()
- B) afterTest()
- C) cleanUp()
- D) removeTest()
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
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
17. When using pytest.raises, you generally test for what?
- A) returned value correctness
- B) time efficiency
- C) expected exceptions
- D) output formatting
18. What is the output of assert "a" in "apple"?
- A) AssertionError
- B) True
- C) False
- D) ValueError
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
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