Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pytest_sqlguard/perf_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _before_cursor_execute_hook(
executemany,
):
"""
See: https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.ConnectionEvents.before_cursor_execute
See: https://docs.sqlalchemy.org/en/20/core/events.html#sqlalchemy.events.ConnectionEvents.before_cursor_execute
"""
if self.format_queries:
statement = sql_format(statement, reindent=True)
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_sqlguard/sql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
SQL fingerprinting code taken from django-perf-rec (version 4.5.0)
SQL fingerprinting code taken from django-perf-rec (version 4.18.0)

https://github.com/adamchainz/django-perf-rec/blob/f8f37896d781f4ab7fb195a5756d25cef43a80d7/src/django_perf_rec/sql.py
"""
Expand Down
16 changes: 8 additions & 8 deletions src/pytest_sqlguard/sqlguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# from core.tasks import task_manager
from pytest_sqlguard.perf_rec import Queries, record_queries

# Optional dependency to enable colored output in record_db_queries()
# Optional dependency to enable colored output in sqlguard()
try:
from termcolor import colored
except ImportError:
Expand Down Expand Up @@ -95,29 +95,29 @@ def sqlguard(

Use it as a context manager:

with record_db_queries():
with sqlguard(session):
...

If you want to use it multiple times in the same test, add a key param:

with record_db_queries(key="first"):
with sqlguard(session, key="first"):
...

with record_db_queries(key="second"):
with sqlguard(session, key="second"):
...

Sometimes you may want to ignore and overwrite already existing reference data:

with record_db_queries(overwrite=True):
with sqlguard(session, overwrite=True):
...

You may also use the `--overwrite-queries-reference-data` pytest flag, or the
`RECORD_DB_QUERIES_OVERWRITE` environment variable to enable this globally.
You may also use the `--sqlguard-overwrite` pytest flag (Or another name you defined in your conftest),
to enable this globally.

If you want to record the complete queries, without removing constants or
parameters to the `SELECT` clause, set `simplify` to `False`:

with record_db_queries(simplify=False):
with sqlguard(session, simplify=False):
...

If expire_all is True (Default), the SQLAlchemy session will expire all its current objects before
Expand Down