This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: regrtest: add -k and -K options to filter tests by function/file names
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: run test cases based on a glob filter
View: 12626
Assigned To: Nosy List: Arfrever, eric.araujo, ezio.melotti, pitrou, r.david.murray, vstinner
Priority: normal Keywords: patch

Created on 2011-05-31 23:56 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
regrtest_regex.patch vstinner, 2011-05-31 23:56 review
regrtest_regex-2.patch vstinner, 2011-07-01 13:44 review
Messages (11)
msg137402 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-31 23:56
Attached patch adds -k/--func-regex and -K/--file-regex options to filter tests by function/file names. It modifies makeSuite() and getTestCaseNames() functions of unittest.loader to add an optional filter argument: callback taking a function name as argument and returning False if the test should be ignored. You can use the new options more than once and their argument are regular expressions (case insensitive).

Examples:

- "./python -m test -k subprocess -K pass_fds" runs only 1 function of 1 file: test_subprocess.test_pass_fds()
- "./python -m test -k os$" runs 1 file: test_os
- "./python -m test -K codecencoding" runs 6 files: test_codecencodings_cn, test_codecencodings_hk, test_codecencodings_iso2022, test_codecencodings_jp, test_codecencodings_kr, test_codecencodings_tw
msg137405 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-06-01 00:11
> Attached patch adds -k/--func-regex and -K/--file-regex options to filter
> tests by function/file names.

We need maybe a third option to filter tests by their class name. And we need 
also maybe the opposite option: exclude tests matching a regex. Another 
proposition: --include and --exclude options using the following format:

<file regex>:<class regex>:<function regex>

Each field is optional, examples:

--include "test_subprocess::leak" ignores test_leak function of 
test_subprocess file
--include "codecencoding::" runs the 6 test_codecencoding* files
--include "test_subprocess:^C:" runs only the tests of the io module (not the 
_pyio module)
- etc.

Problem: --exclude (-x) option is already used.
msg137429 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-06-01 11:15
IMHO it would be better to tweak regrtest so that it understand test_file.TestClass.test_method, possibly supporting wildcards.
E.g.:
  - ./python -m test test_subprocess.POSIXProcessTestCase
  - ./python -m test test_subprocess.POSIXProcessTestCase.test_pass_fds
  - ./python -m test '*codecencoding*'
  - ./python -m test 'test_subprocess.C*'

The -x/--exclude option could be extended to support this notation too and make possible to exclude specific tests classes/methods.
Wildcards are less flexible than regex, but I think they are good enough for our use case and simpler to use.
msg137433 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-01 14:11
+1 to what Ezio said, though I'd rather have this than not have the functionality at all :)
msg137525 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-06-03 15:34
How about reusing unittest discovery in regrtest?
msg137589 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-06-03 21:13
> How about reusing unittest discovery in regrtest?

Does this feature support filtering by keyword for file names and function names?
msg137640 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-06-04 14:39
File name, class name, method name unless I misremember.
msg139581 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-07-01 13:44
regrtest_regex-2.patch: minor update, just ensure that the patch applies correctly on the default branch.
msg141032 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-07-24 01:46
See also #12626 for a similar suggestion.
msg141130 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-07-25 23:33
This patch doesn't work if run_unittest() is called with an already constructed test suite or test case (the patch in #12626 does).
msg149781 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-12-18 16:42
Already fixed in #12626.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56440
2011-12-18 16:42:09pitrousetstatus: open -> closed
resolution: duplicate
messages: + msg149781

superseder: run test cases based on a glob filter
stage: needs patch -> resolved
2011-07-25 23:33:59pitrousetnosy: + pitrou
messages: + msg141130
2011-07-24 01:46:01ezio.melottisetmessages: + msg141032
2011-07-01 13:44:19vstinnersetfiles: + regrtest_regex-2.patch

messages: + msg139581
2011-06-04 14:39:19eric.araujosetmessages: + msg137640
2011-06-03 21:13:36vstinnersetmessages: + msg137589
2011-06-03 15:34:25eric.araujosetnosy: + eric.araujo
messages: + msg137525
2011-06-01 14:11:55r.david.murraysetnosy: + r.david.murray
messages: + msg137433
2011-06-01 11:15:50ezio.melottisetversions: - Python 3.1, Python 2.7, Python 3.2
nosy: + ezio.melotti

messages: + msg137429

type: enhancement
stage: needs patch
2011-06-01 00:11:39vstinnersetmessages: + msg137405
2011-06-01 00:05:43Arfreversetnosy: + Arfrever
2011-05-31 23:56:12vstinnercreate