A small portfolio project showing practical Python debugging, bug explanation, edge-case handling, and test-driven fixes.
This repo contains intentionally broken Python functions, corrected versions, and pytest tests that show the before/after debugging process.
The goal of this project is to demonstrate beginner-to-intermediate Python debugging skills in a clear, practical way.
It shows how to:
- Identify common Python bugs
- Explain why the code fails
- Write cleaner fixed versions
- Add edge-case handling
- Use tests to verify the fix
This type of work matches the kind of help many coding clients need: understanding why code is broken, fixing the issue, and learning how to avoid the same mistake again.
- Python 3
- pytest
- Standard Python library only
python-debugging-lab/
├── debugging_lab/
│ ├── __init__.py
│ ├── broken_examples.py
│ └── fixed_examples.py
├── examples/
│ └── run_examples.py
├── tests/
│ ├── test_broken_examples_expected_failures.py
│ └── test_fixed_examples.py
├── .gitignore
├── requirements.txt
└── README.md
This project includes seven debugging examples:
- Palindrome checker bug
- Full name formatter bug
- Positive number filter bug
- Safe division bug
- Customer record cleanup bug
- Duplicate finder bug
- Date formatter bug
Each example includes:
- A broken version
- A fixed version
- Tests for the fixed version
- Expected-failure tests for the broken version
- Clear comments explaining the issue
Clone the repo:
git clone https://github.com/YOUR-USERNAME/python-debugging-lab.git
cd python-debugging-labCreate and activate a virtual environment:
python -m venv .venvOn Windows:
.venv\Scripts\activateOn macOS/Linux:
source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtRun the tests:
pytestRun the example script:
python examples/run_examples.pydef is_palindrome(text):
return text == text[::-1]Problem: this only works for exact character matches. It fails when the input has uppercase letters, spaces, or punctuation.
Example failure:
is_palindrome("Racecar")
# False, but expected Truedef is_palindrome(text: str) -> bool:
normalized = "".join(char.lower() for char in text if char.isalnum())
return normalized == normalized[::-1]Example result:
is_palindrome("A man, a plan, a canal: Panama")
# True| Example | Bug | Fix |
|---|---|---|
| Palindrome checker | Compared raw text only | Normalize case and remove punctuation |
| Full name formatter | Left messy spaces and failed on missing last name | Strip input and safely join name parts |
| Positive number filter | Included zero and crashed on non-numeric values | Keep only real numbers greater than zero |
| Safe division | Crashed on division by zero | Return None when divisor is zero |
| Customer cleanup | Assumed every dictionary had every key | Use safe defaults and type checks |
| Duplicate finder | Returned repeated duplicate values | Return each duplicate once |
| Date formatter | Accepted only one exact date format | Support multiple common formats |
This project demonstrates practical coding-help skills:
- Reading and understanding existing code
- Finding logic bugs
- Handling edge cases
- Improving function reliability
- Writing simple tests
- Explaining fixes clearly
The broken examples are intentionally incorrect. The tests in test_broken_examples_expected_failures.py are marked with xfail, which means pytest expects them to fail. This makes the debugging process visible without breaking the full test suite.