Skip to content

Commit e3a0670

Browse files
committed
replace atomicwrites with os.replace
1 parent 966d4fb commit e3a0670

File tree

3 files changed

+24
-48
lines changed

3 files changed

+24
-48
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ repos:
6767
- attrs>=19.2.0
6868
- packaging
6969
- tomli
70-
- types-atomicwrites
7170
- types-pkg_resources
7271
- repo: local
7372
hooks:

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ install_requires =
4646
packaging
4747
pluggy>=0.12,<2.0
4848
py>=1.8.2
49-
atomicwrites>=1.0;sys_platform=="win32"
5049
colorama;sys_platform=="win32"
5150
importlib-metadata>=0.12;python_version<"3.8"
5251
tomli>=1.0.0;python_version<"3.11"

src/_pytest/assertion/rewrite.py

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -302,53 +302,31 @@ def _write_pyc_fp(
302302
fp.write(marshal.dumps(co))
303303

304304

305-
if sys.platform == "win32":
306-
from atomicwrites import atomic_write
307-
308-
def _write_pyc(
309-
state: "AssertionState",
310-
co: types.CodeType,
311-
source_stat: os.stat_result,
312-
pyc: Path,
313-
) -> bool:
314-
try:
315-
with atomic_write(os.fspath(pyc), mode="wb", overwrite=True) as fp:
316-
_write_pyc_fp(fp, source_stat, co)
317-
except OSError as e:
318-
state.trace(f"error writing pyc file at {pyc}: {e}")
319-
# we ignore any failure to write the cache file
320-
# there are many reasons, permission-denied, pycache dir being a
321-
# file etc.
322-
return False
323-
return True
324-
325-
else:
326-
327-
def _write_pyc(
328-
state: "AssertionState",
329-
co: types.CodeType,
330-
source_stat: os.stat_result,
331-
pyc: Path,
332-
) -> bool:
333-
proc_pyc = f"{pyc}.{os.getpid()}"
334-
try:
335-
fp = open(proc_pyc, "wb")
336-
except OSError as e:
337-
state.trace(f"error writing pyc file at {proc_pyc}: errno={e.errno}")
338-
return False
305+
def _write_pyc(
306+
state: "AssertionState",
307+
co: types.CodeType,
308+
source_stat: os.stat_result,
309+
pyc: Path,
310+
) -> bool:
311+
proc_pyc = f"{pyc}.{os.getpid()}"
312+
try:
313+
fp = open(proc_pyc, "wb")
314+
except OSError as e:
315+
state.trace(f"error writing pyc file at {proc_pyc}: errno={e.errno}")
316+
return False
339317

340-
try:
341-
_write_pyc_fp(fp, source_stat, co)
342-
os.rename(proc_pyc, pyc)
343-
except OSError as e:
344-
state.trace(f"error writing pyc file at {pyc}: {e}")
345-
# we ignore any failure to write the cache file
346-
# there are many reasons, permission-denied, pycache dir being a
347-
# file etc.
348-
return False
349-
finally:
350-
fp.close()
351-
return True
318+
try:
319+
_write_pyc_fp(fp, source_stat, co)
320+
os.replace(proc_pyc, pyc)
321+
except OSError as e:
322+
state.trace(f"error writing pyc file at {pyc}: {e}")
323+
# we ignore any failure to write the cache file
324+
# there are many reasons, permission-denied, pycache dir being a
325+
# file etc.
326+
return False
327+
finally:
328+
fp.close()
329+
return True
352330

353331

354332
def _rewrite_test(fn: Path, config: Config) -> Tuple[os.stat_result, types.CodeType]:

0 commit comments

Comments
 (0)