Database Testing with pytest
summary
Shows a reproducible pytest setup that tests real Microsoft SQL Server objects using pyodbc connections, fixtures placed in conftest.py, and transaction rollbacks to reset state. Demonstrates unit tests for tables, a view and a stored procedure (including a 4,000‑line SP), finds a miscalculated cost (test saw $100 instead of expected $200) and a bad join that returned 16 rows instead of 8, and fixes both so tests pass. Uses fixture scopes (scope='module') and yield for setup/teardown.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 0:39Accidental DBA journey
- 2:11Unit testing basics
- 3:24Why pytest
- 4:47Testing approach & setup
- 6:15Pytest fixtures
- 7:43Writing test cases
- 8:49Helpful pytest options
- 10:21Building fixtures
- 12:33Managing scope & files
- 13:57Populating test data
- 15:06Example test suite
- 16:32Handling test failures
- 17:41Verification & success
- 20:14Pros and cons
- 22:47Q&A and conclusion







