Files
2026-10-26 14:24:33 +07:00

38 lines
1.6 KiB
Markdown

# Session 9 - Banking Unit Tests (PyTest)
A small local Python project aligned with the Session 9 lecture. It includes conditional banking functions, BVA parametrization, negative tests with `pytest.raises`, a `yield` fixture in `conftest.py`, and a mock of the external notification dependency.
## Run locally
From the project folder:
```bash
python -m venv .venv
```
Activate the virtual environment:
- Windows PowerShell: `.venv\Scripts\Activate.ps1`
- macOS/Linux: `source .venv/bin/activate`
Install dependencies and run tests:
```bash
python -m pip install -r requirements.txt
python -m pytest -v
python -m pytest --cov=banking --cov-branch --cov-report=term-missing --cov-report=html
```
Open `htmlcov/index.html` for the detailed coverage report. The included `coverage_report.txt` contains a verified sample run. No deployment, database, or real notification service is needed.
## Lecture checklist
- Three conditional operations: `deposit`, `withdraw`, `transfer` (plus constructor validation)
- At least eight test cases, including parametrized boundary values
- Multiple negative `pytest.raises` tests
- `yield` fixture with cleanup in `tests/conftest.py`
- `unittest.mock.patch` on `banking.send_notification` (where it is used)
- Statement and branch coverage with a short analysis
Amounts use integer units to avoid floating-point money rounding in this introductory example. `notification_service.py` deliberately raises if called directly: unit tests mock this external dependency. The transfer example is in-memory and not intended as a production banking implementation.