-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix passenv CI in tox ini and make tests insensitive to the presence of the CI env variable #13684
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
Conversation
@webknjaz CI is green again! |
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.
LGTM, but I'll let @RonnyPfannschmidt merge since he was active in the related PR.
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
@RonnyPfannschmidt if you have a few minutes to finalize this review, that would be very appreciated as it would unlock my work to finalize #13679. |
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.
This looks good
Tho only nitpick that comes to mind is that it could be more declarative
But thats a low hanging fruit followup
testing/python/approx.py
Outdated
def test_error_messages_with_different_verbosity( | ||
self, assert_approx_raises_regex, monkeypatch: MonkeyPatch | ||
): | ||
monkeypatch.delenv("CI") |
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 believe we want to remove this env var for all tests, correct?
If so, I suggest you add this autouse fixture to conftest.py
:
@pytest.fixture(autouse=True)
def remove_ci_env_var(monkeypatch: MonkeyPatch) -> None:
"""
Make the test suite insensitive if it is running in CI or not.
If a test requires the variable, it should set it explicitly.
"""
monkeypatch.delenv("CI", raising=False)
Then you can revert the changes done to the 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.
Actually, we might want to use this env var in #13679 to use a longer timeout value in some tests to decrease likelihood of failure on slow CI runners.
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.
To be more specific: there is an existing test named test_timeout
in test_faulhandler.py
that relies on the presence of this variable to adjust the value of the timeout to make it less likely to fail in case the CI runner is too slow (see #7022). However, this strategy never worked as intended because the CI
variable propagation was always blocked by the existing configuration in tox.ini
.
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.
Yeah, I wasn't sure what the impact would be in other places so I didn't suggest making it an autouse fixture.
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 will update the PR to introduce the fixture but not make it auto-use for now.
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.
@nicoddemus @webknjaz @RonnyPfannschmidt done in c34d9b5.
Once merged, I can follow up with a PR to update test_timeout
to remove the skip marker and then trigger the tests on the CI a few times in a row to check that it can properly fix #7022 without having to skip the test entirely on the CI. Then I will update #13679 accordingly.
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.
To be more specific: there is an existing test named test_timeout in test_faulhandler.py that relies on the presence of this variable to adjust the value of the timeout to make it less likely to fail in case the CI runner is too slow
Ahh I see.
In that case we could then create a new mark that skips deleting the env var if present in a test.
@pytest.fixture(autouse=True)
def remove_ci_env_var(monkeypatch: MonkeyPatch, request: pytest.FixtureRequest) -> None:
"""
Make the test insensitive if it is running in CI or not.
Use `@pytest.mark.keep_ci_var` in a test to avoid applying this fixture, letting the test
see the real `CI` variable (if present).
"""
has_keep_ci_mark = request.node.get_closest_marker("keep_ci_var") is not None
if not has_keep_ci_mark:
monkeypatch.delenv("CI", raising=False)
We can apply this mark to test_timeout
and any other test that requires seeing the real CI
variable.
@ogrisel I understand this is PR is a side quest just to work on #13679, but would mind give the autouse fixture a go? I think the time to try this approach is now that we have someone on hands on the issue.
If there are too many breakages and you decide to not deal with them now, feel free to revert the autouse
change and merge as is currently.
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'm leaving pre-approved. Would appreciate you giving the autouse approach one more try before merging though.
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.
Alright, let me give this a try.
testing/test_faulthandler.py
Outdated
), | ||
False, | ||
], | ||
) |
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 removed the skip
mark on test_timeout
to check whether the keep_ci_var
works as expected.
Previously, this test would have failed with high probability on at least one of the CI runner. Now that we propagate the CI variable, it seems that this test pass on most of the CI runners but we got still got one failure: https://github.com/pytest-dev/pytest/actions/runs/17409387341/job/49422461654?pr=13684
Let me re-add the skip mark for now to decouple the different PRs.
So |
Thanks @ogrisel. Bummer that |
Backport to 8.4.x: 💚 backport PR created✅ Backport PR branch: Backported as #13694 🤖 @patchback |
…of the CI env variable (#13684) As discussed in #13684. --------- Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]> (cherry picked from commit bf92deb)
…of the CI env variable (#13684) (#13694) As discussed in #13684. --------- (cherry picked from commit bf92deb) Co-authored-by: Olivier Grisel <[email protected]> Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
Attempted to make `test_faulthandler.py::test_timeout` more reliable on CI, but ultimately this was not accomplished. However, it seems flushing `stdout` and `stderr` during `pytester.run` seems the right thing to do, so it was decided to leave the calls and only skip the test in more specific scenarios that were failing frequently on CI (see #13695 for discussion history). We should extend the skip list as needed. Follow-up on #13684. Partially addresses #7022.
See: #13679 (comment)