Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#14378 closed (fixed)

Enable customization of the class for self.client in tests

Reported by: nedbatchelder Owned by: nedbatchelder
Component: Testing framework Version: 1.2
Severity: Keywords:
Cc: nedbatchelder Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The attached patch removes the hard connection between test.TestCase and test.client.Client, instead making the class of client a class attribute on TestCase. This allows sub-classes of TestCase to specify a custom sub-class of Client to use in their tests.

While it's possible to create your own self.client in a setUp method, this keeps the code simpler. For example, I could set this class attribute once on my own base TestCase class, and all my test cases would use it without having to invoke setUp on the base class, just as the built-in TestCase class does.

Attachments (1)

custom-test-client.diff (2.4 KB) - added by nedbatchelder 6 years ago.
the patch

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by nedbatchelder

the patch

comment:1 Changed 6 years ago by nedbatchelder

  • Owner changed from nobody to nedbatchelder
  • Status changed from new to assigned

comment:2 Changed 6 years ago by nedbatchelder

  • Cc nedbatchelder added

comment:3 Changed 6 years ago by russellm

  • milestone set to 1.3
  • Triage Stage changed from Unreviewed to Ready for checkin

Looks good to me. Thanks for the idea and patch, Ned.

comment:4 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [14058]) Fixed #14378 -- Made the test client class customizable. Thanks to Ned Batchelder for the patch.

comment:5 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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