Opened 10 years ago
Closed 10 years ago
#24118 closed New feature (fixed)
Add --debug-sql option to tests to print SQL queries on failure
Reported by: | Marc Tamlyn | Owned by: | Marc Tamlyn |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It's a common problem (*especially* when working on ORM code) to want to print the complete sql queries run during a failing test, especially when parts of the run sql are in the traceback...
I've created a POC which adds this feature by customising parts of unittest. The --debug-sql
option is provided to both ./runtests.py
and ./manage.py test
.
Change History (8)
comment:1 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
comment:3 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:4 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 10 years ago
Resolution: | fixed |
---|---|
Severity: | Normal → Release blocker |
Status: | closed → new |
Triage Stage: | Ready for checkin → Accepted |
The output without the --debug-sql
flag and with --verbosity=3
is broken here. The test name doesn't show in the output for ERROR
. I haven't checked FAILURE
though.
test_squashmigrations_optimizes (migrations.test_commands.SquashMigrationsTest) ... ok test_squashmigrations_squashes (migrations.test_commands.SquashMigrationsTest) ... ok test_ticket_23799_squashmigrations_no_optimize (migrations.test_commands.SquashMigrationsTest) ... ok ERROR ERROR ERROR ERROR ERROR test_create_model (migrations.test_multidb.MultiDBOperationTests) ... ok test_create_model2 (migrations.test_multidb.MultiDBOperationTests) ... ok
comment:6 by , 10 years ago
Has patch: | unset |
---|
comment:7 by , 10 years ago
And another output I can't remember to have seen before. Again w/o the flag:
test_wsgirequest_repr (requests.tests.RequestsTests) ... ok test_wsgirequest_with_force_script_name (requests.tests.RequestsTests) ... ok test_wsgirequest_with_script_name (requests.tests.RequestsTests) ... ok skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' skipped 'Selenium tests not requested' ERROR ERROR ERROR
But a few lines below:
MySQL implicitly rolls back savepoints when it deadlocks (#22291). ... skipped 'MySQL-specific behaviors'
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I have verified this is not a regression and is a result of tests failing outside of the test (during TransactionTestCase._pre_setup()
) due to migrations being out of sync. The same behaviour is generated without the original fixing commit.
In b5c1a85b50c709770b8e98aeecfeb8e81ca29dcf: