In this snippet, I've outlined a query plugin for pytest which gives a warning for tests which use more than 10 queries (threshold is configurable using pytest.mark.max_queries(N).

This would give us the ability to proactively guard against N+1 queries and implement appropriate prefetching.