MCPcopy
hub / github.com/pytest-dev/pytest / _write_pyc

Function _write_pyc

src/_pytest/assertion/rewrite.py:318–340  ·  view source on GitHub ↗
(
    state: AssertionState,
    co: types.CodeType,
    source_stat: os.stat_result,
    pyc: Path,
)

Source from the content-addressed store, hash-verified

316
317
318def _write_pyc(
319 state: AssertionState,
320 co: types.CodeType,
321 source_stat: os.stat_result,
322 pyc: Path,
323) -> bool:
324 proc_pyc = f"{pyc}.{os.getpid()}"
325 try:
326 with open(proc_pyc, "wb") as fp:
327 _write_pyc_fp(fp, source_stat, co)
328 except OSError as e:
329 state.trace(f"error writing pyc file at {proc_pyc}: errno={e.errno}")
330 return False
331
332 try:
333 os.replace(proc_pyc, pyc)
334 except OSError as e:
335 state.trace(f"error writing pyc file at {pyc}: {e}")
336 # we ignore any failure to write the cache file
337 # there are many reasons, permission-denied, pycache dir being a
338 # file etc.
339 return False
340 return True
341
342
343def _rewrite_test(fn: Path, config: Config) -> tuple[os.stat_result, types.CodeType]:

Callers 3

test_write_pycMethod · 0.90
test_read_pyc_successMethod · 0.90
exec_moduleMethod · 0.85

Calls 2

_write_pyc_fpFunction · 0.85
traceMethod · 0.80

Tested by 2

test_write_pycMethod · 0.72
test_read_pyc_successMethod · 0.72