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 Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Marc Tamlyn, 10 years ago

Needs documentation: unset
Needs tests: unset

comment:3 by Tim Graham, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Marc Tamlyn <marc.tamlyn@…>, 10 years ago

Resolution: fixed
Status: newclosed

In b5c1a85b50c709770b8e98aeecfeb8e81ca29dcf:

Fixed #24118 -- Added --debug-sql option for tests.

Added a --debug-sql option for tests and runtests.py which outputs the
SQL logger for failing tests. When combined with --verbosity=2, it also
outputs the SQL for passing tests.

Thanks to Berker, Tim, Markus, Shai, Josh and Anssi for review and
discussion.

comment:5 by Markus Holtermann, 10 years ago

Resolution: fixed
Severity: NormalRelease blocker
Status: closednew
Triage Stage: Ready for checkinAccepted

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 Tim Graham, 10 years ago

Has patch: unset

comment:7 by Markus Holtermann, 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 Marc Tamlyn, 10 years ago

Resolution: fixed
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top