Opened 9 years ago

Closed 9 years ago

#25062 closed New feature (wontfix)

assertNoWriteQueries Assertion

Reported by: frewsxcv Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords: testing assert assertion
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Similar to:

https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.TransactionTestCase.assertNumQueries

It would make sure no databases get written to within the block.

Change History (3)

comment:1 by Moritz Sichert, 9 years ago

Why not just use this?

with self.assertNumQueries(0):
    # some code

comment:2 by Tim Graham, 9 years ago

I think the distinction here is that read queries are allowed, but not writes. I'm curious about the use case. There is #22492 which proposes a way to prohibit queries in a given code block. Perhaps that idea could be extended to prohibit write queries in a block. That may be less fragile than a test assertion.

comment:3 by Tim Graham, 9 years ago

Resolution: wontfix
Status: newclosed

Closing absent follow up from the reporter.

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