Opened 4 years ago

Closed 4 years ago

#30245 closed New feature (fixed)

Run tests matching a filter (Python 3.7 -k option)

Reported by: François Freitag Owned by: François Freitag
Component: Testing framework Version: dev
Severity: Normal Keywords: test, unittest, filter
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


With Python 3.7, the unittest module got a -k option (as in keyword), to run tests matching a given keyword. Corresponding entry in the Python 3.7 unittest release note entry. Associated python issue:

The feature seems to be coming from the py.test project feature running tests by keyword expression. The feature is also available in other testing frameworks, such as PHPUnit's --filter option.

Adding a similar feature to Django would facilitate test selection. Since -k is already the short-hand for --keepdb, it may make more sense to implement another flag, maybe --filter?

Change History (8)

comment:1 Changed 4 years ago by François Freitag

comment:2 Changed 4 years ago by Carlton Gibson

Triage Stage: UnreviewedAccepted

Hi François. Yes, this seems a good addition to me.

... -k is already the short-hand for ...

My initial thought here would be to re-take -k to match unittest. I'm pretty sure us having contrary flags is just going to be a royal-pain forever.
A small-BC change there is preferable.

"We're adding -k to mean ... following unittest. Use long --keepdb flag instead." — but maybe people want a short flag too. (???)

I guess we need to ask on the DevelopersMailingList. Can I ask you to post there to begin the discussion? (I can do it if you don't have a moment.)


Last edited 4 years ago by Carlton Gibson (previous) (diff)

comment:3 Changed 4 years ago by François Freitag

Hi Carlton,

Thank you for looking into this ticket. I'll present the case to the mailing list today or tomorrow.


comment:4 Changed 4 years ago by Carlton Gibson

Patch needs improvement: set

Marking "Patch needs improvement" until we hear back from the mailing list discussion.

comment:6 Changed 4 years ago by François Freitag

Patch needs improvement: unset

Following mailing list consensus to remove the -k shorthand for --keepdb without replacement, the PR has been updated and uses -k to select tests.

comment:7 Changed 4 years ago by Jon Dufresne

Triage Stage: AcceptedReady for checkin

comment:8 Changed 4 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 568eed9:

Fixed #30245 -- Added -k option to DiscoverRunner.

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