Opened 19 months ago

Last modified 19 months ago

#26659 new New feature

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

Description

As described here:
https://groups.google.com/d/msg/django-developers/W6YiFg9ITg0/BAOTHezHBgAJ

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 manage.py test \
mydjangoapp.app_one.tests.test_module.TestClass.test_method_1

we could have this:

$ python manage.py 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 19 months ago.

Download all attachments as: .zip

Change History (5)

Changed 19 months ago by Antonio Piraino

Attachment: patch.diff added

comment:1 Changed 19 months ago by Antonio Piraino

Easy pickings: set
Needs documentation: set

comment:2 Changed 19 months ago by Tim Graham

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 Changed 19 months ago by Tim Graham

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

comment:4 Changed 19 months ago by Tommy Beadle

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

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