Skip to content
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

RuntimeError: generator raised StopIteration when fixing #113

Closed
alexmojaki opened this issue Sep 13, 2024 · 2 comments
Closed

RuntimeError: generator raised StopIteration when fixing #113

alexmojaki opened this issue Sep 13, 2024 · 2 comments

Comments

@alexmojaki
Copy link

  1. Clone https://github.com/pydantic/logfire
  2. make install
  3. pytest --inline-snapshot=fix

Results in:

Traceback (most recent call last):
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/inline_snapshot/_inline_snapshot.py", line 284, in check
    old_value_element, old_node_element = next(old)
                                          ^^^^^^^^^
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/alex/work/logfire/.venv/bin/pytest", line 8, in <module>
    sys.exit(console_main())
             ^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 201, in console_main
    code = main()
           ^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 175, in main
    ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/main.py", line 330, in pytest_cmdline_main
    return wrap_session(config, _main)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/main.py", line 318, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/logging.py", line 868, in pytest_sessionfinish
    return (yield)
            ^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 124, in _multicall
    teardown.send(result)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/terminal.py", line 903, in pytest_sessionfinish
    self.config.hook.pytest_terminal_summary(
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/terminal.py", line 925, in pytest_terminal_summary
    return (yield)
            ^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/_pytest/warnings.py", line 132, in pytest_terminal_summary
    return (yield)
            ^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/inline_snapshot/pytest_plugin.py", line 218, in pytest_terminal_summary
    for change in snapshot._changes():
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/inline_snapshot/_inline_snapshot.py", line 753, in _changes
    yield from self._value._get_changes()
  File "/Users/alex/work/logfire/.venv/lib/python3.12/site-packages/inline_snapshot/_inline_snapshot.py", line 398, in _get_changes
    yield from check(self._old_value, self._ast_node, self._new_value)
RuntimeError: generator raised StopIteration

You will also see a test failure caused by #112, that's unrelated, the same error happens when the test is deleted.

No tests need fixing. pytest alone passes fine. If I wrap the offending loop body in inline-snapshot with:

try:
    ...
except StopIteration:
    break

then pytest --inline-snapshot=fix completes fine without making any changes. I'm guessing this happens when generating the Update snapshots report, which BTW I would be quite happy to not see at all.

@15r10nk
Copy link
Owner

15r10nk commented Sep 18, 2024

Sorry that this took so long.

Your problem is caused by your *issue_lines in your snapshots.

The following example has also a problem (but a different exception)

from inline_snapshot import snapshot


def test_star():
    values = [1]
    assert [0, 1, 5] == snapshot([0, *values, 5])

Can you work for now without star expressions in snapshots?
I find your tests really cool and star expressions can be really useful with snapshots, but the problem is that they are not supported by the current implementation.

I will check for them and warn the user that snapshots with star-expressions are currently not supported. I hope this is ok for you.

I will also look into your updates and try to figure out why they are so noisy.

@15r10nk
Copy link
Owner

15r10nk commented Sep 24, 2024

fixed in 0.13.2

@15r10nk 15r10nk closed this as completed Sep 24, 2024
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

No branches or pull requests

2 participants