Description
Bug report
Bug description:
I noticed this via Hypothesis' pretty-printer for lambda
functions, and tracked the divergence through the inspect
module to linecache
:
import linecache
def test():
print(linecache.cache["<string>"]) # expected to raise KeyError
assert False
If I run this snippet with python3.13 -Wignore -m pytest repro.py
, or any older Python version, you'll get the expected KeyError
. But if I append -n2
to the command, it prints (44, None, ['import sys;exec(eval(sys.stdin.readline()))\n'], '<string>')
!
(python3.13 -m pip install pytest pytest-xdist
will get the dependencies for this)
That's the popen
bootstrap line from execnet
, which handles running code across multiple processes for pytest-xdist
. At this point I've found linecache.cache.pop("<string>", None)
to be an acceptable workaround, and since I don't have any particular knowledge of either the CPython or execnet code that's as far as I investigated.
CPython versions tested on:
3.8, 3.9, 3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
- gh-117174: Add a new route in linecache to fetch interactive source code #117500
- gh-112730: Respect tests that require environment variables with no-colorize fixes #118288
- [3.13] gh-117174: Add a new route in linecache to fetch interactive source code (GH-117500) #131060
- gh-117174: Adapt test_multiple_statements_fail_early now that we have always source #131065
- gh-117174: Fix reference leak and gdb tests #131095
- [3.13] gh-117174: Fix reference leak and gdb tests (GH-131095) #131120
- gh-117174: Skip test_gdb if Python is built with LTO #131143
- gh-117174: Adapt
test_multiple_statements_fail_early
to new REPL behavior (follow-up gh-131065) #131836 - [3.13] gh-117174: Adapt
test_multiple_statements_fail_early
to new REPL behavior (follow-up gh-131065) (GH-131836) #131841 - [3.13] gh-117174: Adapt test_multiple_statements_fail_early now that we have always source (GH-131065) #131850