Closed
Description
- a detailed description of the bug or problem you are havingoutput of
pip list
from the virtual environment you are usingpytest and operating system versionsminimal example if possible
I ask the user in inline-snapshot for approval if he wants to fix the snapshot values, but this does not work for cpython 3.13.
I can only reproduce this problem with pytest.
The problem can be reproduced like this:
conftest.py
def pytest_terminal_summary(config):
capture = config.pluginmanager.getplugin("capturemanager")
capture.suspend_global_capture(in_=True)
print("Enter 'hi'")
value = input()
print()
print("value:",repr(value))
assert value == "hi"
capture.resume_global_capture()
test_example.py
def example():
print("unimportant example")
Running pytest asks for "hi" but value will always be an empty string no matter what you type.
But it work when you use pytest -s
and type "hi" or echo hi | pytest
.
I can only reproduce this problem using cpython 3.13, it worked for older versions.
uv pip list:
Package Version
--------- -------
iniconfig 2.0.0
packaging 24.2
pluggy 1.5.0
pytest 8.3.4
os: linux/debian
Metadata
Metadata
Assignees
Labels
No labels
Activity
The-Compiler commentedon Jan 29, 2025
Are you using an uv-installed Python as well? If so, can you try with a vanilla upstream Python 3.13? I suspect this is the same underlying issue as #12888.
15r10nk commentedon Jan 29, 2025
You are right. I compiled v3.13.1 myself and the example worked.
The-Compiler commentedon Jan 29, 2025
I actually can't reproduce with this example even with an uv-managed Python 3.13.0 (
uv venv -p 3.13 --python-preference=only-managed .venv
).From what I could gather this should only be happening if something does
import readline
, which shouldn't be the case here. Could you show the full output of runningpython -v -m pytest
with this reproducer?15r10nk commentedon Jan 29, 2025
I removed all existing venvs and created a new one
The-Compiler commentedon Jan 29, 2025
Hmm, so
readline
is getting imported in your case, not for me:Maybe
python -X importtime -m pytest
would reveal where it's coming from? Also maybe try if installing pytest-workaround-12888 · PyPI (which forces an earlyreadline
import) helps here too.15r10nk commentedon Jan 29, 2025
This is the last part of the imports
15r10nk commentedon Jan 29, 2025
and Yes, the workaround solves the issue.
15r10nk commentedon Jan 30, 2025
Would you recommend to use pytest-workaround-12888 · PyPI as a dependency to fix this problem in production?
The-Compiler commentedon Jan 30, 2025
Thanks for all the infos! It looks like this is indeed another way the issue in #12888 manifests, I missed that it got triggered by pdb doing
import rlcompleter
as well. I'll try to cook up a minimal example, but it might be difficult if on my machine for some reasonimport rlcompleter
doesn't trigger the issue (anymore?).I only happened to notice that package in the references when scrolling through that issue, but I trust both the company behind it (Sentry) as well as its author (Anthony Sottile who is a former pytest core maintainer). I'm assuming the package is mostly on PyPI for easy usage for Sentry projects, but if you're okay with that (and it e.g. potentially vanishing once they don't need it anymore), I'd say go for it (and thanks @asottile-sentry!).
Add readline workaround for libedit
The-Compiler commentedon Jan 30, 2025
Pushed a PR with a workaround:
asottile-sentry commentedon Jan 30, 2025
yeah that package should work well as a workaround -- all it does is insert an import during process startup via a
.pth
fileunfortunately we're currently stuck on an old version of pytest (due to rerunfailures) so it was necessary for us
15r10nk commentedon Jan 31, 2025
I fixed it by adding this to my
pytest_plugin.py
:I didn't want to add an additional dependency to my project (which would probably have to be packaged by the distributions)
Thank you very much for your help.
Add readline workaround for libedit (#13176)
Add readline workaround for libedit (#13176)
Add readline workaround for libedit (#13176)