-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-108828: Support selecting tests by labels #108829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
6ea2f47
16ee29f
fe7fcd0
5ae7161
4f41c75
c884b55
22d68c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -482,6 +482,8 @@ The :mod:`test.support` module defines the following functions: | |||||
| ``True`` if called by a function whose ``__name__`` is ``'__main__'``. | ||||||
| Used when tests are executed by :mod:`test.regrtest`. | ||||||
|
|
||||||
| If called at the top level, sets label "requires\_\ *resource*" on the module. | ||||||
|
|
||||||
|
|
||||||
| .. function:: sortdict(dict) | ||||||
|
|
||||||
|
|
@@ -498,16 +500,34 @@ The :mod:`test.support` module defines the following functions: | |||||
| rather than looking directly in the path directories. | ||||||
|
|
||||||
|
|
||||||
| .. function:: mark(label, *, globals=None) | ||||||
|
|
||||||
| Add a label to tests. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| The ``@mark('label')`` decorator adds a label to method or class. | ||||||
| ``test.support.mark('label', globals=globals())`` adds a label to the whole | ||||||
| module. | ||||||
|
|
||||||
| Many :mod:`test.support` decorators like :func:`requires_resource`, | ||||||
| :func:`~test.support.cpython_only` or :func:`bigmemtest` add labels | ||||||
| automatically. | ||||||
|
|
||||||
|
|
||||||
| .. function:: match_test(test) | ||||||
|
|
||||||
| Determine whether *test* matches the patterns set in :func:`set_match_tests`. | ||||||
| Determine whether *test* matches the patterns set in :func:`set_match_tests` | ||||||
| and labels set in :func:`set_match_tests2`. | ||||||
|
|
||||||
|
|
||||||
| .. function:: set_match_tests(accept_patterns=None, ignore_patterns=None) | ||||||
|
|
||||||
| Define match patterns on test filenames and test method names for filtering tests. | ||||||
|
|
||||||
|
|
||||||
| .. function:: set_match_tests2(accept_labels=None, ignore_labels=None) | ||||||
|
|
||||||
| Define labels on tests for filtering. | ||||||
|
|
||||||
|
|
||||||
| .. function:: run_unittest(*classes) | ||||||
|
|
||||||
| Execute :class:`unittest.TestCase` subclasses passed to the function. The | ||||||
|
|
@@ -774,26 +794,31 @@ The :mod:`test.support` module defines the following functions: | |||||
| .. decorator:: requires_zlib | ||||||
|
|
||||||
| Decorator for skipping tests if :mod:`zlib` doesn't exist. | ||||||
| Adds label "requires_zlib". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: requires_gzip | ||||||
|
|
||||||
| Decorator for skipping tests if :mod:`gzip` doesn't exist. | ||||||
| Adds label "requires_gzip". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: requires_bz2 | ||||||
|
|
||||||
| Decorator for skipping tests if :mod:`bz2` doesn't exist. | ||||||
| Adds label "requires_bz2". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: requires_lzma | ||||||
|
|
||||||
| Decorator for skipping tests if :mod:`lzma` doesn't exist. | ||||||
| Adds label "requires_lzma". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: requires_resource(resource) | ||||||
|
|
||||||
| Decorator for skipping tests if *resource* is not available. | ||||||
| Adds label "requires\_\ *resource*". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: requires_docstrings | ||||||
|
|
@@ -810,13 +835,16 @@ The :mod:`test.support` module defines the following functions: | |||||
| .. decorator:: cpython_only | ||||||
|
|
||||||
| Decorator for tests only applicable to CPython. | ||||||
| Adds label "impl_detail_cpython". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: impl_detail(msg=None, **guards) | ||||||
|
|
||||||
| Decorator for invoking :func:`check_impl_detail` on *guards*. If that | ||||||
| returns ``False``, then uses *msg* as the reason for skipping the test. | ||||||
|
|
||||||
| For every keyword argument *name* adds a label | ||||||
| "impl_detail\_\ *name*" if its value is true or | ||||||
| "impl_detail_no\_\ *name*" otherwise. | ||||||
|
|
||||||
| .. decorator:: no_tracing | ||||||
|
|
||||||
|
|
@@ -845,10 +873,13 @@ The :mod:`test.support` module defines the following functions: | |||||
| method may be less than the requested value. If *dry_run* is ``False``, it | ||||||
| means the test doesn't support dummy runs when ``-M`` is not specified. | ||||||
|
|
||||||
| Adds label "bigmemtest". | ||||||
|
|
||||||
|
|
||||||
| .. decorator:: bigaddrspacetest | ||||||
|
|
||||||
| Decorator for tests that fill the address space. | ||||||
| Adds label "bigaddrspacetest". | ||||||
|
|
||||||
|
|
||||||
| .. function:: check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=None) | ||||||
|
|
@@ -1630,6 +1661,8 @@ The :mod:`test.support.import_helper` module provides support for import tests. | |||||
| optional for others, set *required_on* to an iterable of platform prefixes | ||||||
| which will be compared against :data:`sys.platform`. | ||||||
|
|
||||||
| If called at the top level, sets label "requires\_\ *name*" on the module. | ||||||
|
|
||||||
| .. versionadded:: 3.1 | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,14 @@ def __init__(self, ns: Namespace): | |
| self.ignore_tests: FilterTuple = tuple(ns.ignore_tests) | ||
| else: | ||
| self.ignore_tests = None | ||
| if ns.accept_labels: | ||
| self.accept_labels: tuple[str, ...] = tuple(ns.accept_labels) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reasons they should be immutable, as well as In any case, I am planning to rewrite filtering by names. Instead of two tuples there will be more complex structure where order matters. And the same can be used for labels. |
||
| else: | ||
| self.accept_labels = None | ||
| if ns.ignore_labels: | ||
| self.ignore_labels: tuple[str, ...] = tuple(ns.ignore_labels) | ||
| else: | ||
| self.ignore_labels = None | ||
| self.exclude: bool = ns.exclude | ||
| self.fromfile: StrPath | None = ns.fromfile | ||
| self.starting_test: TestName | None = ns.start | ||
|
|
@@ -484,6 +492,8 @@ def main(self, tests: TestList | None = None): | |
| list_cases(selected, | ||
| match_tests=self.match_tests, | ||
| ignore_tests=self.ignore_tests, | ||
| accept_labels=self.accept_labels, | ||
| ignore_labels=self.ignore_labels, | ||
| test_dir=self.test_dir) | ||
| else: | ||
| exitcode = self.run_tests(selected, tests) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to always call them "marks". The main reason is that
pytestuses the same idea and pytest's marks are well-known.Right now
markfunction adds a "label". It does not sound right.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can always call it "label".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is similar to pytest's markers, but there are enough differences in applying them and filtering by them. I do not have preference, "label", "marker" and "tag" are all look like synonyms in this context to me.