Django: Test client's context is empty from the shell

前端 未结 1 1912
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 08:19

I cannot access the context attribute of an HttpResponse object from ipython. But the unit test accesses context.

Here is the unit

1条回答
  •  隐瞒了意图╮
    2021-02-09 09:04

    You can see in the Django test code where it monkeypatches in special instrumentation to make template rendering send a signal, which the test client listens to so it can annotate the response object with the rendered templates and their contexts.

    For this signal to be attached, you'd have to either call the django.test.utils.setup_test_environment() function in your shell session (which has other side effects), or duplicate just the lines that monkeypatch template rendering. Not too hard, but I agree it'd be nice if this particular debugging aspect could be refactored out to make it easier to use outside of tests. Personally I wouldn't mind if this information was always collected when DEBUG is True, not just under test.

    0 讨论(0)
提交回复
热议问题