menu

Python Testing and Debugging


1. 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


2. Which tool in Python can be used for load testing?

locust

pytest-benchmark

httperf

all of the above


3. 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


4. What is a test fixture in Python testing?

A set of preconditions that must be met before a test can be run

A function that sets up the environment for a test

A set of test cases that are run together

A function that tears down the environment after a test


5. What is a logical error in Python?

An error that occurs when the code is not valid Python syntax

An error that occurs when the program runs out of memory

An error that occurs when the program encounters unexpected input

An error that occurs when the program produces incorrect output due to a flaw in the logic


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

unittest

pytest

doctest

all of the above


7. What is unit testing in Python?

Testing individual units or components of code in isolation

Testing the entire program as a whole

Testing user interface interactions

Testing database connections


8. Which module is used for logging in Python?

logging

unittest

traceback

sys


9. 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


10. What is a mock object in Python?

An object that simulates the behavior of a real object in a controlled way

An object that is used to bypass security measures in a program

An object that is used to test network connections

An object that is used to generate random data for testing