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

Function test_collect_short_file_windows

testing/test_collection.py:1760–1782  ·  view source on GitHub ↗

Reproducer for #11895: short paths not collected on Windows.

(pytester: Pytester)

Source from the content-addressed store, hash-verified

1758
1759@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only")
1760def test_collect_short_file_windows(pytester: Pytester) -> None:
1761 """Reproducer for #11895: short paths not collected on Windows."""
1762 short_path = tempfile.mkdtemp()
1763 if "~" not in short_path: # pragma: no cover
1764 if running_on_ci():
1765 # On CI, we are expecting that under the current GitHub actions configuration,
1766 # tempfile.mkdtemp() is producing short paths, so we want to fail to prevent
1767 # this from silently changing without us noticing.
1768 pytest.fail(
1769 f"tempfile.mkdtemp() failed to produce a short path on CI: {short_path}"
1770 )
1771 else:
1772 # We want to skip failing this test locally in this situation because
1773 # depending on the local configuration tempfile.mkdtemp() might not produce a short path:
1774 # For example, user might have configured %TEMP% exactly to avoid generating short paths.
1775 pytest.skip(
1776 f"tempfile.mkdtemp() failed to produce a short path: {short_path}, skipping"
1777 )
1778
1779 test_file = Path(short_path).joinpath("test_collect_short_file_windows.py")
1780 test_file.write_text("def test(): pass", encoding="UTF-8")
1781 result = pytester.runpytest(short_path)
1782 assert result.parseoutcomes() == {"passed": 1}
1783
1784
1785def test_collect_short_file_windows_multi_level_symlink(

Callers

nothing calls this directly

Calls 6

running_on_ciFunction · 0.90
mkdtempMethod · 0.80
failMethod · 0.80
write_textMethod · 0.80
parseoutcomesMethod · 0.80
runpytestMethod · 0.45

Tested by

no test coverage detected