GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — use Contextmanagers to handle StopIteration in generators by RonnyPfannschmidt · Pull Request #12934 · pytest-dev/pytest

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Nov 3, 2024

Copy link
Copy Markdown
Member
  • prepare example test for stopiteration passover issue
  • WIP: use contextmanagers instead of yield from

yield from is a generator boundary that transfers StopIteration into a RuntimeError

closes #12929

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@RonnyPfannschmidt RonnyPfannschmidt added this to the 8.4 milestone Nov 12, 2024
Tusenka
Tusenka approved these changes Dec 9, 2024
View reviewed changes
@graingert

graingert commented Dec 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

src/_pytest/threadexception.py and src/_pytest/unraisableexception.py both use regular trylast hooks instead of generators, so the conflicts can be resolved by checking them out from main

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert reviewed Dec 19, 2024
View reviewed changes
Comment thread testing/example_scripts/hook_exceptions/test_stop_iteration.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert reviewed Jan 10, 2025
View reviewed changes
Comment thread testing/acceptance_test.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@graingert

graingert commented Jan 10, 2025

Copy link
Copy Markdown
Member

this won't pass without a new Pluggy release

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nicoddemus

nicoddemus commented Mar 1, 2025

Copy link
Copy Markdown
Member

@RonnyPfannschmidt what is the status here? Do you plan to make a pluggy release yourself?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RonnyPfannschmidt

RonnyPfannschmidt commented Mar 1, 2025

Copy link
Copy Markdown
Member Author

Indeed

I intend to give this priority by the end of the month

nicoddemus and graingert reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

RonnyPfannschmidt added 3 commits March 27, 2025 07:33
@RonnyPfannschmidt
prepare example test for stopiteration passover issue
040b787
@RonnyPfannschmidt
WIP: use contextmanagers instead of yield from
24b1cd8
as it turns out, StopIteration is not transparent on the boundaries of generators

# Conflicts:
#	src/_pytest/threadexception.py
#	src/_pytest/unraisableexception.py
@RonnyPfannschmidt
fixup rebase
4f9cf8d
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the bug-stopiteration-hook branch from 69e78b7 to 4f9cf8d Compare March 27, 2025 07:27
@RonnyPfannschmidt
rebase fixup more
c69bb2a
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the bug-stopiteration-hook branch from f92fb28 to c69bb2a Compare March 27, 2025 07:43
@graingert

graingert commented Mar 27, 2025

Copy link
Copy Markdown
Member

@RonnyPfannschmidt I wrote some test cases for this, I hope you find them useful:

def test_stop_iteration_from_collect(pytester: Pytester) -> None:
    pytester.makepyfile(test_it="raise StopIteration('hello')")
    result = pytester.runpytest()
    assert result.ret == ExitCode.INTERRUPTED
    result.assert_outcomes(failed=0, passed=0, errors=1)
    result.stdout.fnmatch_lines(
        [
            "=========================== short test summary info ============================",
            "ERROR test_it.py - StopIteration: hello",
            "!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!",
            "=============================== 1 error in * ===============================",
        ]
    )


def test_stop_iteration_runtest_protocol(pytester: Pytester) -> None:
    pytester.makepyfile(
        test_it="""
        import pytest
        @pytest.fixture
        def fail_setup():
            raise StopIteration(1)
        def test_fail_setup(fail_setup):
            pass
        def test_fail_teardown(request):
            def stop_iteration():
                raise StopIteration(2)
            request.addfinalizer(stop_iteration)
        def test_fail_call():
            raise StopIteration(3)
        """
    )
    result = pytester.runpytest()
    assert result.ret == ExitCode.TESTS_FAILED
    result.assert_outcomes(failed=1, passed=1, errors=2)
    result.stdout.fnmatch_lines(
        [
            "=========================== short test summary info ============================",
            "FAILED test_it.py::test_fail_call - StopIteration: 3",
            "ERROR test_it.py::test_fail_setup - StopIteration: 1",
            "ERROR test_it.py::test_fail_teardown - StopIteration: 2",
            "==================== 1 failed, 1 passed, 2 errors in * =====================",
        ]
    )
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert

graingert commented Mar 27, 2025

Copy link
Copy Markdown
Member

note this is still currently blocked by a release of pytest-dev/pluggy#545

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RonnyPfannschmidt

RonnyPfannschmidt commented Mar 27, 2025

Copy link
Copy Markdown
Member Author

i intend to land pytest-dev/pluggy#546 as before the next release of pluggy

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

graingert and others added 5 commits May 29, 2025 19:42
@graingert
Merge branch 'main' into bug-stopiteration-hook
ccaf348
@graingert
add tests
1e67ca5
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
1701ce1
for more information, see https://pre-commit.ci
@graingert
remove hook_exceptions examples - these are tests now
d6d20a5
@graingert
add changelog
e6211c2
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label May 31, 2025
graingert added 3 commits May 31, 2025 18:23
@graingert
Merge branch 'main' into bug-stopiteration-hook
08c56c4
@graingert
handle different numbers of ===
a617f94
@graingert
handle different numbers of !!!
7e3f5e1
@graingert
graingert marked this pull request as ready for review May 31, 2025 18:27
graingert
graingert approved these changes May 31, 2025
View reviewed changes
@graingert
graingert requested review from jakkdl and nicoddemus May 31, 2025 18:27
@graingert
Merge branch 'main' into bug-stopiteration-hook
54b2f67
@RonnyPfannschmidt

RonnyPfannschmidt commented May 31, 2025

Copy link
Copy Markdown
Member Author

im ok with squashing

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert
graingert merged commit 075c5ef into pytest-dev:main May 31, 2025
@RonnyPfannschmidt
RonnyPfannschmidt deleted the bug-stopiteration-hook branch October 4, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@graingert graingert graingert approved these changes
@jakkdl jakkdl Awaiting requested review from jakkdl
@nicoddemus nicoddemus Awaiting requested review from nicoddemus
+1 more reviewer
@Tusenka Tusenka Tusenka approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Milestone

8.4

Development

Successfully merging this pull request may close these issues.

tests raising StopIteration break pytest/pluggy

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@RonnyPfannschmidt @graingert @nicoddemus @Tusenka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.