10000 gh-108828: Support selecting tests by labels by serhiy-storchaka · Pull Request #108829 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108828: Support selecting tests by labels #108829

New issue 8000

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member
@serhiy-storchaka serhiy-storchaka commented Sep 2, 2023

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement tests Tests in the Lib/test dir needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Sep 2, 2023
@serhiy-storchaka serhiy-storchaka marked this pull request as ready for review September 3, 2023 09:56
@vstinner
Copy link
Member
vstinner commented Sep 5, 2023

If possible, I would prefer to land my PR #108858 before.

@brettcannon brettcannon removed their request for review September 5, 2023 22:05
Copy link
Member
@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this, it is definetely a step in the right direction for our test suite.

I have a question about naming, though.
Some tests in Lib/test/test_regrtest.py would also be nice, or I can add them later :)

I already have several ideas on top of this PR!

@@ -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)
Copy link
Member

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 pytest uses the same idea and pytest's marks are well-known.

Suggested change
.. function:: mark(label, *, globals=None)
.. function:: mark(name, *, globals=None)

Right now mark function adds a "label". It does not sound right.

Copy link
Member

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".

Copy link
Member Author

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.

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add a label to tests.
Add a mark to tests.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set[str]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reasons they should be immutable, as well as match_tests and ignore_tests.

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.

@@ -1002,16 +1015,41 @@ def wrapper(self):
#=======================================================================
# unittest integration.

def _id(obj):
return obj
def mark(label, *, globals=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a similar API in one of my OS libs, users didn't like it at all :(

I think it would be better to use mark(..., *, module=False)

This way we can:

  1. Simplify the API for readers (even if our users are people working on CPython)
  2. Use frame hack to get the needed globals()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like to depend on such hack it tests. If it does not work, many unrelated tests will not even be able to load.

Since it is an internal API used in limited number of places, simplicity for users is less important. support.mark('gui', globals=globals()) is not much worse than support.mark('gui', module=True)

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes and removed needs backport to 3.11 only security fixes labels May 9, 2024
@Yhg1s Yhg1s removed the needs backport to 3.12 only security fixes label Apr 8, 2025
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0