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

Function test_safe_exists

testing/test_pathlib.py:1213–1239  ·  view source on GitHub ↗
(tmp_path: Path)

Source from the content-addressed store, hash-verified

1211
1212
1213def test_safe_exists(tmp_path: Path) -> None:
1214 d = tmp_path.joinpath("some_dir")
1215 d.mkdir()
1216 assert safe_exists(d) is True
1217
1218 f = tmp_path.joinpath("some_file")
1219 f.touch()
1220 assert safe_exists(f) is True
1221
1222 # Use unittest.mock() as a context manager to have a very narrow
1223 # patch lifetime.
1224 p = tmp_path.joinpath("some long filename" * 100)
1225 with unittest.mock.patch.object(
1226 Path,
1227 "exists",
1228 autospec=True,
1229 side_effect=OSError(errno.ENAMETOOLONG, "name too long"),
1230 ):
1231 assert safe_exists(p) is False
1232
1233 with unittest.mock.patch.object(
1234 Path,
1235 "exists",
1236 autospec=True,
1237 side_effect=ValueError("name too long"),
1238 ):
1239 assert safe_exists(p) is False
1240
1241
1242def test_import_sets_module_as_attribute(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 2

safe_existsFunction · 0.90
mkdirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…