Python doctests for inline testing
Aug 18, 2025
Python’s doctest
module allows you to write tests directly in docstrings by mimicking interactive Python sessions. Simply write >>>
followed by Python code and the expected output on the next line.
"""
Add two numbers.
>>> add(2, 3)
5
>>> add(-1, 1)
0
"""
return +
Run with python -m doctest filename.py
or include doctest.testmod()
in your script. Great for keeping examples and tests close to the code they document.
Python binarytree library for tree visualization
Aug 18, 2025
The binarytree
library provides an easy way to generate, visualize, and manipulate binary trees in Python. Install with pip install binarytree
.
# Create a tree manually
=
=
=
# Generate random trees
=
Perfect for algorithm practice, education, or debugging tree-based code. The ASCII visualization makes it easy to understand tree structure at a glance.