Opened 8 years ago

Closed 5 years ago

#26659 closed New feature (duplicate)

Allow filtering of which tests run

Reported by: Antonio Piraino Owned by: nobody
Component: Testing framework Version: 1.9
Severity: Normal Keywords: tests
Cc: Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


As described here:

we could add a new, optional parameter to filter only a desired set of (comma separated) test methods instead of writing the full path for a single test or run an entire class/package. Example, instead of this:

$ python test \

we could have this:

$ python test --method-filter test_method_1,test_method_2,...

Another improvement this patch implements (as suggested in that django-dev thread) is the possibility to have the full path to the failing test to be easily copied and pasted. This is implemented adding a SimpleTextTestResult class.

These are especially useful for running only failing tests.

If the ticket is accepted, I'll write the documentation too.

Attachments (1)

patch.diff (3.0 KB ) - added by Antonio Piraino 8 years ago.

Download all attachments as: .zip

Change History (6)

by Antonio Piraino, 8 years ago

Attachment: patch.diff added

comment:1 by Antonio Piraino, 8 years ago

Easy pickings: set
Needs documentation: set

comment:2 by Tim Graham, 8 years ago

Component: UncategorizedTesting framework
Easy pickings: unset
Patch needs improvement: set
Triage Stage: UnreviewedSomeday/Maybe

I'm more convinced by Josh's proposal on the mailing list thread about the possibility of using glob-style patterns. Perhaps adding a new parameter to the test runner isn't needed. I'd also like to see if any other testing tools implement something similar. The problem this ticket aims to address doesn't seem Django specific.

The change in the output format was proposed in #23332. Perhaps you could try addressing the Python issue spawned by that ticket. We might consider reopening the Django ticket in light of your solution if the issue cannot be addressed upstream. For future reference, please don't combined multiple features in a single ticket.

comment:3 by Tim Graham, 8 years ago

Summary: New parameter for test methods filteringAllow filtering of which tests run

comment:4 by Tommy Beadle, 8 years ago

py.test gives you the ability to select tests by
1) full path (test ID)
2) using a "-k <value>" command-line option to select tests that include <value> in the name/path
3) passing --lf to run the tests that failed during the last run

comment:5 by Baptiste Mispelon, 5 years ago

Resolution: duplicate
Status: newclosed

Correct me if I'm wrong, but I'm going to mark this as a duplicate of #30245 which implemented unittest's -k option [1].

I think is pretty close to what the original report was asking for since you can now write something like $ python test -k test_method_*.


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