Opened 8 years ago

Closed 8 years ago

#26981 closed New feature (fixed)

Support passing custom kwargs to DiscoverRunner's test runner

Reported by: Chris Jerdonek Owned by: Chris Jerdonek
Component: Testing framework Version: dev
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

Currently, there doesn't seem to be a nice way to have Django pass custom kwargs to the underlying unittest test runner when running tests.

This is because Django hard-codes the kwargs it passes (see here for a direct link to the code):

def run_suite(self, suite, **kwargs):
    resultclass = self.get_resultclass()
    return self.test_runner(
        verbosity=self.verbosity,
        failfast=self.failfast,
        resultclass=resultclass,
    ).run(suite)

Django's default test runner is unittest.TextTestRunner, and here are all of the kwargs that the runner currently supports (from the function signature in Python 3.5.2):

class TextTestRunner(object):

    def __init__(self, stream=None, descriptions=True, verbosity=1,
                 failfast=False, buffer=False, resultclass=None, warnings=None,
                 *, tb_locals=False):

One approach to this ticket might involve having run_suite() pass its kwargs along to the test runner function (instead of "swallowing" them), and making whatever other code changes are needed to support this (e.g. modifying run_tests() to pass kwargs along to run_suite()). More focused approaches are also possible.

Change History (6)

comment:1 by Chris Jerdonek, 8 years ago

Also, to ground this in reality, the use case I am / was interested in is passing a custom stream to the underlying TextTestRunner.

comment:2 by Chris Jerdonek, 8 years ago

Owner: changed from nobody to Chris Jerdonek
Status: newassigned
Version: 1.9master

comment:3 by Chris Jerdonek, 8 years ago

I started working on this in branch ticket_26981 of my GitHub repo.

comment:4 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature

comment:5 by Chris Jerdonek, 8 years ago

Has patch: set

I posted a pull request for this in my GitHub repo here.

comment:6 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In ebed9ee8:

Fixed #26981 -- Added DiscoverRunner.get_test_runner_kwargs().

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