Skip to content

gh-108828: Support selecting tests by labels - #108829

Open
serhiy-storchaka wants to merge 7 commits into
python:mainfrom
serhiy-storchaka:libregrtest-labels
Open

gh-108828: Support selecting tests by labels#108829
serhiy-storchaka wants to merge 7 commits into
python:mainfrom
serhiy-storchaka:libregrtest-labels

Conversation

@serhiy-storchaka

@serhiy-storchakaserhiy-storchaka commented Sep 2, 2023

Copy link
Copy Markdown
Member

@serhiy-storchakaserhiy-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
Copy Markdown
Member

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

@brettcannon
brettcannon removed their request for review September 5, 2023 22:05

@sobolevnsobolevn left a comment

Copy link
Copy Markdown
Member

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!

Comment threadDoc/library/test.rst
rather than looking directly in the path directories.


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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

Comment threadDoc/library/test.rst

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

Add a label to tests.

Copy link
Copy Markdown
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.

Comment threadLib/test/libregrtest/main.py Outdated
else:
self.ignore_tests = None
if ns.accept_labels:
self.accept_labels: tuple[str, ...] = tuple(ns.accept_labels)

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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.


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

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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-storchakaserhiy-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
@Yhg1sYhg1s removed the needs backport to 3.12 only security fixes label Apr 8, 2025
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 13, 2026
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 30, 2026
@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label Jun 5, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesneeds backport to 3.15pre-release feature fixes, bugs and security fixestestsTests in the Lib/test dirtype-featureA feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@serhiy-storchaka@vstinner@sobolevn@Yhg1s@bedevere-bot