Skip to content

Add Coverage workflow #623

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

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Add Coverage workflow #623

wants to merge 25 commits into from

Conversation

Daraan
Copy link
Contributor

@Daraan Daraan commented Jul 7, 2025

Added a coverage workflow (resolves: #520).

Currently the logic is to upload one coverage file from each version test.

pip install coverage & coverage -m unittest

A crucial point about this workflow is that it installs and runs the test with coverage -m unittest and not python -m unittest anymore. coverage does (currently) not install typing_extensions so I think that is a safe pip install (at the moment). I tried to add a weak test that assures that typing_extensions.__file__ is indeed the one in src/ and not site-packages, but that test fails on the pypi installation


Do you prefer any changes here? e.g. run first with python when install and run again with coverage?

Does anyone know why the pypy 3.9 and 3.10 tests fail here? Some kind of code leakage, missing monkeypatch?

EDIT:

  • Changed to not run coverage on the pypi versions

@AlexWaygood
Copy link
Member

if it's a pain to run PyPy tests under coverage, I think it would be fine to do the pypy tests as a separate CI job that aren't run under coverage. None of our code is currently PyPy-specific (we had a workaround for a PyPy bug for a while but it was a tiny branch of code).

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@AlexWaygood
Copy link
Member

Could you fix the pre-commit failures?

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM if we can get the PR comment thing working! (I don't think I have the necessary permissions for that either)

@Daraan
Copy link
Contributor Author

Daraan commented Jul 7, 2025

According to https://docs.github.com/actions/how-tos/security-for-github-actions/security-guides/automatic-token-authentication, a PR from a fork can never have write access (expect the repo itself).

A relevant bit:

Finally, if the workflow was triggered by a pull request from a forked repository, and the Send write tokens to workflows from pull requests setting is not selected, the permissions are adjusted to change any write permissions to read only.


Maintainers note from the action on the error: https://github.com/marocchino/sticky-pull-request-comment/tree/v2/#error-resource-not-accessible-by-integration

check your Settings > Actions > General > Workflow permissions, and make sure to enable read and write permissions.

The alternative is to provide a GITHUB_TOKEN (defaults to ${{ github.token }}) currently.

@Daraan
Copy link
Contributor Author

Daraan commented Aug 13, 2025

@JelleZijlstra I think we need your decision / help here to finish this PR.
If we want to have a coverage report message the action needs write permission on the PR, see links above for the options.
We could also use codecov. I thought it also required a secret token, on a second look it might also without (on public repos). It comes with its own pros and cons.

contents: read
pull-requests: write

if: ${{ always() }}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A matter of choice, I thought it might be interesting to always get the coverage output comment even if the tests failed.
The brackets {{ might not be needed on a second look. On !cancelled might even be better.

What are you thoughts? I will adjust if you feel differently (i.e. only on success).

Copy link
Member

Choose a reason for hiding this comment

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

So having this line means it runs even if a previous run failed? My thinking was just that this line sounds redundant, it seems like if True:.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, this is a magic function -- docs here: https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#always

we use it for similar reasons in the third-party workflow to make sure that the create-issue-on-failure job is triggered even if one of the jobs in the needs list failed (usually if a job in the needs list fails, it cancels any other jobs that list it as required):

needs:
- pydantic
- typing_inspect
- pycroscope
- typeguard
- typed-argument-parser
- mypy
- cattrs
- sqlalchemy
if: >-
${{
github.repository == 'python/typing_extensions'
&& always()
&& github.event_name == 'schedule'
&& (
needs.pydantic.result == 'failure'
|| needs.typing_inspect.result == 'failure'
|| needs.pycroscope.result == 'failure'
|| needs.typeguard.result == 'failure'
|| needs.typed-argument-parser.result == 'failure'
|| needs.mypy.result == 'failure'
|| needs.cattrs.result == 'failure'
|| needs.sqlalchemy.result == 'failure'
)
}}

@JelleZijlstra
Copy link
Member

Read and write permissions for workflows are already enabled, so this might work once we merge it into main?

Copy link
Contributor Author

@Daraan Daraan left a comment

Choose a reason for hiding this comment

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

Read and write permissions for workflows are already enabled, so this might work once we merge it into main?

I had the same thought as well. But couldn't find a definite answer yet.

On my fork I did made a PR to a branch with the coverage workflow already in it: Daraan#1 (comment) there it commented like expected on the PR.
However, if I add a PR too my main branch Daraan#2 it also comments -might be because it is my own PR 🤔?

If: Settings > Actions > General > Workflow permissions is read & write. Merge and test with a dummy PR as follow up if it really works?

contents: read
pull-requests: write

if: ${{ always() }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A matter of choice, I thought it might be interesting to always get the coverage output comment even if the tests failed.
The brackets {{ might not be needed on a second look. On !cancelled might even be better.

What are you thoughts? I will adjust if you feel differently (i.e. only on success).

@Daraan Daraan marked this pull request as draft August 18, 2025 13:47
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me! I'm happy to merge and iterate a bit more if it doesn't work properly.

@Daraan
Copy link
Contributor Author

Daraan commented Aug 18, 2025

I'll do a rewrite of the PR. In short a fork can never have a PR comment on pull_request as the permissions / secret is not accessible. I'll shift it to something that should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add test coverage monitoring
3 participants