|
3 | 3 | import pprint
|
4 | 4 | import shutil
|
5 | 5 | import sys
|
| 6 | +import tempfile |
6 | 7 | import textwrap
|
7 | 8 | from typing import List
|
8 | 9 |
|
| 10 | +from _pytest.assertion.util import running_on_ci |
9 | 11 | from _pytest.config import ExitCode
|
10 | 12 | from _pytest.fixtures import FixtureRequest
|
11 | 13 | from _pytest.main import _in_venv
|
@@ -1758,3 +1760,29 @@ def test_foo(): assert True
|
1758 | 1760 |
|
1759 | 1761 | assert result.ret == ExitCode.OK
|
1760 | 1762 | assert result.parseoutcomes() == {"passed": 1}
|
| 1763 | + |
| 1764 | + |
| 1765 | +@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only") |
| 1766 | +def test_collect_short_file_windows(pytester: Pytester) -> None: |
| 1767 | + """Reproducer for #11895: short paths not colleced on Windows.""" |
| 1768 | + short_path = tempfile.mkdtemp() |
| 1769 | + if "~" not in short_path: # pragma: no cover |
| 1770 | + if running_on_ci(): |
| 1771 | + # On CI, we are expecting that under the current GitHub actions configuration, |
| 1772 | + # tempfile.mkdtemp() is producing short paths, so we want to fail to prevent |
| 1773 | + # this from silently changing without us noticing. |
| 1774 | + pytest.fail( |
| 1775 | + f"tempfile.mkdtemp() failed to produce a short path on CI: {short_path}" |
| 1776 | + ) |
| 1777 | + else: |
| 1778 | + # We want to skip failing this test locally in this situation because |
| 1779 | + # depending on the local configuration tempfile.mkdtemp() might not produce a short path: |
| 1780 | + # For example, user might have configured %TEMP% exactly to avoid generating short paths. |
| 1781 | + pytest.skip( |
| 1782 | + f"tempfile.mkdtemp() failed to produce a short path: {short_path}, skipping" |
| 1783 | + ) |
| 1784 | + |
| 1785 | + test_file = Path(short_path).joinpath("test_collect_short_file_windows.py") |
| 1786 | + test_file.write_text("def test(): pass", encoding="UTF-8") |
| 1787 | + result = pytester.runpytest(short_path) |
| 1788 | + assert result.parseoutcomes() == {"passed": 1} |
0 commit comments