#33026: The Testing Tools docs should highlight RequestFactory
-----------------------------------------+------------------------
Reporter: Roy Smith | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
I've used django.test.Client for several large projects over the years.
Recently, I got stuck because I couldn't get session management to work in
my tests. Judging from the number of StackOverflow, etc, posts on this
topic, this is a common issue. Eventually I found
https://stackoverflow.com/questions/25132621/ which put me onto using
RequestFactory instead of the Test Client. I'm sure I'd seen
RequestFactory mentioned before, but never explored it.
I think RequestFactory should be emphasized more in
https://docs.djangoproject.com/en/3.1/topics/testing/tools/. Right now,
the only mention is buried deep down on the page in a "See also" box which
links to the "Advanced testing topics". Labeling it as an "advanced"
topic is misleading. ​May I suggest that it should be at least briefly
covered in the introductory section. There's already a couple of
paragraphs contrasting django.test.client to Selenium. It would be good
to say something like:
A lower-level alternative to the test client is RequestFactory, which lets
you bypass the routing and middleware layers. Use RequestFactory to write
unit tests of individual view functions and methods. Use the test client
to write integration tests of how your views work in the context of your
full application. Use Selenium to test rendered HTML and the behavior of
Web pages, namely JavaScript functionality.
I'd be happy to write up an improved doc if you think this is a reasonable
way to go.
--
Ticket URL: <https://code.djangoproject.com/ticket/33026>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.569783be3947d9207625243a8667717e%40djangoproject.com.