Skip to content

Commit f52d637

Browse files
committed
Add test for #11895
1 parent 0d91539 commit f52d637

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

testing/test_collection.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import pprint
55
import shutil
66
import sys
7+
import tempfile
78
import textwrap
89
from typing import List
910

11+
from _pytest.assertion.util import running_on_ci
1012
from _pytest.config import ExitCode
1113
from _pytest.fixtures import FixtureRequest
1214
from _pytest.main import _in_venv
@@ -1742,3 +1744,29 @@ def test_foo(): assert True
17421744

17431745
assert result.ret == ExitCode.OK
17441746
assert result.parseoutcomes() == {"passed": 1}
1747+
1748+
1749+
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only")
1750+
def test_collect_short_file_windows(pytester: Pytester) -> None:
1751+
"""Reproducer for #11895: short paths not colleced on Windows."""
1752+
short_path = tempfile.mkdtemp()
1753+
if "~" not in short_path:
1754+
if running_on_ci():
1755+
# On CI, we are expecting that under the current GitHub actions configuration,
1756+
# tempfile.mkdtemp() is producing short paths, so we want to fail to prevent
1757+
# this from silently changing without us noticing.
1758+
pytest.fail(
1759+
f"tempfile.mkdtemp() failed to produce a short path on CI: {short_path}"
1760+
)
1761+
else:
1762+
# We want to skip failing this test locally in this situation because
1763+
# depending on the local configuration tempfile.mkdtemp() might not produce a short path:
1764+
# For example, user might have configured %TEMP% exactly to avoid generating short paths.
1765+
pytest.skip(
1766+
f"tempfile.mkdtemp() failed to produce a short path: {short_path}, skipping"
1767+
)
1768+
1769+
test_file = Path(short_path).joinpath("test_collect_short_file_windows.py")
1770+
test_file.write_text("def test(): pass", encoding="UTF-8")
1771+
result = pytester.runpytest(short_path)
1772+
assert result.parseoutcomes() == {"passed": 1}

0 commit comments

Comments
 (0)