Skip to content

Conversation

ogrisel
Copy link
Contributor

@ogrisel ogrisel commented Aug 28, 2025

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 28, 2025
@webknjaz webknjaz added the backport 8.4.x apply to PRs at any point; backports the changes to the 8.4.x branch label Aug 28, 2025
@ogrisel
Copy link
Contributor Author

ogrisel commented Aug 28, 2025

@webknjaz CI is green again!

Copy link
Member

@webknjaz webknjaz left a 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]>
@ogrisel
Copy link
Contributor Author

ogrisel commented Sep 1, 2025

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

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a 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

def test_error_messages_with_different_verbosity(
self, assert_approx_raises_regex, monkeypatch: MonkeyPatch
):
monkeypatch.delenv("CI")
Copy link
Member

@nicoddemus nicoddemus Sep 1, 2025

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

@nicoddemus nicoddemus Sep 2, 2025

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

),
False,
],
)
Copy link
Contributor Author

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.

@ogrisel
Copy link
Contributor Author

ogrisel commented Sep 2, 2025

So keep_ci_var seems to work as expected. Unfortunately, increasing the timeout conditionally on the presence of the CI variable does not seem to be enough to reliably fix #7022 as observed in #13684 (comment).

@nicoddemus
Copy link
Member

Thanks @ogrisel.

Bummer that test_timeout still fails on occasion.

@nicoddemus nicoddemus merged commit bf92deb into pytest-dev:main Sep 2, 2025
36 checks passed
Copy link

patchback bot commented Sep 2, 2025

Backport to 8.4.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.4.x/bf92debb4fd874289f6aed29c6947b611b1de0ae/pr-13684

Backported as #13694

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Sep 2, 2025
…of the CI env variable (#13684)

As discussed in #13684.

---------

Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
(cherry picked from commit bf92deb)
nicoddemus pushed a commit that referenced this pull request Sep 2, 2025
…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]>
@ogrisel ogrisel deleted the passenv-ci-in-tox-ini branch September 3, 2025 07:39
nicoddemus pushed a commit that referenced this pull request Sep 9, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.4.x apply to PRs at any point; backports the changes to the 8.4.x branch bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants