|
4 | 4 | import pprint
|
5 | 5 | import shutil
|
6 | 6 | import sys
|
| 7 | +import tempfile |
7 | 8 | import textwrap
|
8 | 9 | from typing import List
|
9 | 10 |
|
| 11 | +from _pytest.assertion.util import running_on_ci |
10 | 12 | from _pytest.config import ExitCode
|
11 | 13 | from _pytest.fixtures import FixtureRequest
|
12 | 14 | from _pytest.main import _in_venv
|
@@ -1742,3 +1744,29 @@ def test_foo(): assert True
|
1742 | 1744 |
|
1743 | 1745 | assert result.ret == ExitCode.OK
|
1744 | 1746 | 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