Opened 3 years ago

Closed 19 months ago

Last modified 19 months ago

#33026 closed Cleanup/optimization (fixed)

The Testing Tools docs should highlight RequestFactory

Reported by: Roy Smith Owned by: Chris Wedgwood
Component: Documentation Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (7)

comment:1 by Carlton Gibson, 3 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Hey Roy, OK — very happy to look at a suggestion here. Thanks.

comment:2 by Chris Wedgwood, 19 months ago

Owner: changed from nobody to Chris Wedgwood
Status: newassigned

comment:4 by Mariusz Felisiak, 19 months ago

Patch needs improvement: set

comment:5 by Chris Wedgwood, 19 months ago

Patch needs improvement: unset

comment:6 by GitHub <noreply@…>, 19 months ago

Resolution: fixed
Status: assignedclosed

In 468d0610:

Fixed #33026 -- Mentioned RequestFactory in testing tools docs.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 19 months ago

In 7607fc89:

[4.1.x] Fixed #33026 -- Mentioned RequestFactory in testing tools docs.

Backport of 468d06109778e3656229ac28c9019ea7246f9b79 from main

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