Testing and Debugging
This section outlines how to verify and troubleshoot the application’s behavior.
Testing
The application relies on unit tests for validating its functionality. Each component is isolated and tested independently to ensure correctness. Unit tests are written in Python and reside in the tests
directory. To run the tests, execute the following command from the project’s root directory:
pytest
Debugging
The run-python-helix-app
application provides multiple options for debugging.
1. Print Statements
The most basic debugging technique is to add print statements to the code. This allows you to inspect the values of variables at various points in the code execution.
Example:
def my_function(x, y):
print(f"x: {x}, y: {y}")
result = x + y
print(f"result: {result}")
return result
2. Logging
The logging
module in Python provides a more structured and flexible approach to logging. This allows you to control the level of detail and destination of logs.
Example:
import logging
logging.basicConfig(level=logging.DEBUG)
def my_function(x, y):
logging.debug(f"x: {x}, y: {y}")
result = x + y
logging.debug(f"result: {result}")
return result
3. Python Debugger (pdb)
The pdb
module provides a powerful interactive debugger that allows you to step through code line by line, inspect variables, and execute arbitrary code.
Example:
import pdb
def my_function(x, y):
pdb.set_trace()
result = x + y
return result
4. IDE Debugger
Most Integrated Development Environments (IDEs) offer integrated debuggers that provide features such as breakpoints, variable inspection, and call stack visualization.
5. Helix Debugger
The Helix editor offers a built-in debugger, which is more efficient and has more features. The Helix debugger requires installing the helix-debug
plugin.
Example:
- Install the
helix-debug
plugin. - Start the debugger from the
helix-debug
menu. - Set breakpoints by clicking in the gutter beside the line numbers.
- Run the application.
- The debugger will pause at the breakpoints.
- Use the debugger controls to step through code, inspect variables, and evaluate expressions.
6. Using Logs
The run-python-helix-app
application also provides the ability to write logs to a file for troubleshooting. To enable logging, set the LOG_FILE
environment variable to the desired file path. The logs will include debug information about the application’s execution.
Example:
LOG_FILE=/tmp/app.log run-python-helix-app
Note: The logs provide valuable information during troubleshooting, but they may contain sensitive data. Consider security implications when choosing a location for log files.