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
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ description = "Context manager to upload explain plans to https://explain.dalibo
authors = [{ name = "william chu", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Framework :: Django :: 5.2",
]
dependencies = [
"django>=3.2,<5.2.0",
"django>=3.2,<6.0",
"psycopg2~=2.9.0",
"sqlglot>=18.13.0",
]
Expand Down
14 changes: 11 additions & 3 deletions tests/test_explain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import connection
from django.test import TestCase
from time import sleep

from django_pev import explain
from example.school.models import Student, Subject, Teacher
Expand All @@ -22,11 +23,17 @@ def test_explain_captures_queries(self):
with explain(db_alias="default") as e:
list(Student.objects.filter(name="lol"))
Student.objects.create(name="1")
list(Student.objects.raw("select school_student.*, pg_sleep(0.01) from school_student"))
list(
Student.objects.raw(
"select school_student.*, pg_sleep(0.01) from school_student"
)
)

assert e.n_queries == 3, "We should have captured 3 queries"

assert "PG_SLEEP" in e.slowest.sql, "The slowest query should be the one with pg_sleep"
assert (
"PG_SLEEP" in e.slowest.sql
), "The slowest query should be the one with pg_sleep"

def test_upload_plan_to_dalibo(self):
# We can upload results to dalibo
Expand All @@ -45,7 +52,8 @@ def test_open_visualization_in_browser(self):
list(Student.objects.filter(name="1"))

pev_result = e.slowest.visualize_in_browser()

# give dalibo a fighting chance to display the result in the browser
sleep(5)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the delete is pretty fast otherwise meaning that the browser doesn't have a chance to actually show the result... doing this means that we see a result (not that it matters in practice)

pev_result.delete()

def test_optimization_prompt(self):
Expand Down
Loading