menu

Python Testing and Debugging


1. What is the purpose of a test runner in Python testing?

To run tests and report the results

To generate test data for use in testing

To analyze code performance during testing

To identify and fix errors in test code


2. What is the purpose of the finally block in Python?

To catch errors and handle them gracefully

To output messages to the user

To verify database connections

To ensure code is executed regardless of whether an exception is raised


3. Which method is used to raise an exception in Python?

raise Exception("Error message")

assert Exception("Error message")

print Exception("Error message")

throw Exception("Error message")


4. What is a breakpoint in Python?

A location in the code where the program stops running

A location in the code where the program starts running

A location in the code where the program outputs a message

A location in the code where the program skips a line


5. Which module in Python provides support for unit testing?

unittest

pytest

doctest

all of the above


6. What is a traceback in Python?

A list of the functions that were called before an exception occurred

A list of the functions that will be called next

A list of the variables that are currently in scope

A list of the variables that were modified by the last function call


7. What is an assertion in Python testing?

A statement that tests whether a condition is true

A statement that generates a warning message

A statement that terminates program execution

A statement that logs a message to a file


8. What is the purpose of the try-except block in Python?

To catch errors and handle them gracefully

To output messages to the user

To verify database connections

To test user interface interactions


9. What is a regression test?

A test that verifies the entire system

A test that verifies a single function or module

A test that verifies changes made to the code do not cause existing functionality to break

A test that verifies the database


10. Which tool is used for profiling Python code?

cProfile

unittest

logging

pdb