-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: - [ ] doc - [ ] use a command line option instead? I've thought about having a fixture also, but it would require to set "force_debug_cursor" on the connections then, and it probably not useful; typically you want to use this for a short time only - therefore a command line option might be better suited also (but you can use `-o django_debug_sql = 1`). And on the other hand, it will only show up on failures, and is therefore maybe good to set it in general.
- Loading branch information
Showing
3 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
def test_debug_sql_setting(django_testdir): | ||
django_testdir.create_test_module( | ||
""" | ||
import pytest | ||
from .app.models import Item | ||
@pytest.mark.django_db | ||
def test_fail_with_db_queries(): | ||
assert Item.objects.count() == 0 | ||
assert 0, "triggered failure" | ||
""" | ||
) | ||
django_testdir.makeini( | ||
""" | ||
[pytest] | ||
django_debug_sql = 1 | ||
""" | ||
) | ||
|
||
result = django_testdir.runpytest_subprocess() | ||
assert result.ret == 1 | ||
result.stdout.fnmatch_lines([ | ||
"*- Captured log setup -*", | ||
"*CREATE TABLE*", | ||
"*- Captured log call -*", | ||
"*SELECT COUNT*", | ||
]) | ||
|
||
|
||
def test_debug_sql_with_django_setup(django_testdir): | ||
django_testdir.create_test_module( | ||
""" | ||
import pytest | ||
from .app.models import Item | ||
@pytest.mark.django_db | ||
def test_fail_with_db_queries(): | ||
import django | ||
django.setup() | ||
assert Item.objects.count() == 0 | ||
assert 0, "triggered failure" | ||
""" | ||
) | ||
django_testdir.makeini( | ||
""" | ||
[pytest] | ||
django_debug_sql = 1 | ||
""" | ||
) | ||
|
||
result = django_testdir.runpytest_subprocess() | ||
assert result.ret == 1 | ||
result.stdout.fnmatch_lines([ | ||
# "*- Captured stdout setup -*", | ||
"*- Captured log setup -*", | ||
"*CREATE TABLE*", | ||
"*= warnings summary =*", | ||
"*Debug logging level of django.db.backends was changed (to 0).*", | ||
]) | ||
assert "SELECT COUNT" not in result.stdout.str() |