Introduction
As covered in the articles on Network Profiler and Sleep Profiler, Qase provides powerful tools for monitoring and analyzing test scenarios. This article explains Database Profiler—a tool that automatically tracks and logs database operations.
The Problem with Databases in Tests
In integration and E2E tests, the database is critical. Without profiling it’s hard to see:
- Which queries ran and how long they took
- Why tests are slow: which specific query is the bottleneck
- Where to debug: the exact query text and error message
- How much data changed: number of affected rows
What is Database Profiler
Database Profiler intercepts SQL queries and sends each call to Qase as a separate step. You see the query text, execution time, affected rows, and connection info.
How Database Profiler Works
It relies on monkey patching and proxy classes: the profiler wraps query execution methods, measures their time, and sends the data to Qase TestOps as test steps.
Usage Example (PostgreSQL + pytest)
import psycopg2
from qase.pytest import qase
@qase.title("User Database Operations Test")
def test_user_operations():
conn = psycopg2.connect(
host="localhost",
port=5432,
database="testdb",
user="testuser",
password="testpass",
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE id = %s", (1,))
user = cursor.fetchone()
cursor.execute(
"UPDATE users SET email = %s WHERE id = %s",
("[email protected]", 1),
)
conn.commit()
cursor.execute("SELECT COUNT(*) FROM users")
count = cursor.fetchone()[0]
assert count > 0
conn.close()

Configuration
Via command line
# Enable only Database Profiler
pytest --qase-profilers=db
# Combine with other profilers
pytest --qase-profilers=db,network,sleep
Via qase.config.json
{
"mode": "testops",
"profilers": ["db"],
"testops": {
"api": {
"host": "qase.io"
}
}
}
Conclusion
Database Profiler gives full visibility into SQL queries in tests: query text, timing, affected rows, and connection context. It accelerates bottleneck analysis, simplifies debugging, and helps keep tests stable and fast.