|
9 | 9 | from typing import List
|
10 | 10 |
|
11 | 11 | from _pytest.assertion.util import running_on_ci
|
12 |
| -from _pytest.compat import ensure_long_path |
13 | 12 | from _pytest.config import ExitCode
|
14 | 13 | from _pytest.fixtures import FixtureRequest
|
15 | 14 | from _pytest.main import _in_venv
|
@@ -1764,43 +1763,27 @@ def test_foo(): assert True
|
1764 | 1763 | assert result.parseoutcomes() == {"passed": 1}
|
1765 | 1764 |
|
1766 | 1765 |
|
1767 |
| -class TestCollectionShortPaths: |
1768 |
| - @pytest.fixture |
1769 |
| - def short_path(self) -> Path: |
1770 |
| - short_path = tempfile.mkdtemp() |
1771 |
| - if "~" not in short_path: # pragma: no cover |
1772 |
| - if running_on_ci(): |
1773 |
| - # On CI, we are expecting that under the current GitHub actions configuration, |
1774 |
| - # tempfile.mkdtemp() is producing short paths, so we want to fail to prevent |
1775 |
| - # this from silently changing without us noticing. |
1776 |
| - pytest.fail( |
1777 |
| - f"tempfile.mkdtemp() failed to produce a short path on CI: {short_path}" |
1778 |
| - ) |
1779 |
| - else: |
1780 |
| - # We want to skip failing this test locally in this situation because |
1781 |
| - # depending on the local configuration tempfile.mkdtemp() might not produce a short path: |
1782 |
| - # For example, user might have configured %TEMP% exactly to avoid generating short paths. |
1783 |
| - pytest.skip( |
1784 |
| - f"tempfile.mkdtemp() failed to produce a short path: {short_path}, skipping" |
1785 |
| - ) |
1786 |
| - return Path(short_path) |
1787 |
| - |
1788 |
| - @pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only") |
1789 |
| - def test_ensure_long_path_win(self, short_path: Path) -> None: |
1790 |
| - long_path = ensure_long_path(short_path) |
1791 |
| - assert len(os.fspath(long_path)) > len(os.fspath(short_path)) |
1792 |
| - |
1793 |
| - @pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only") |
1794 |
| - def test_collect_short_file_windows( |
1795 |
| - self, pytester: Pytester, short_path: Path |
1796 |
| - ) -> None: |
1797 |
| - """Reproducer for #11895: short paths not collected on Windows.""" |
1798 |
| - test_file = short_path.joinpath("test_collect_short_file_windows.py") |
1799 |
| - test_file.write_text("def test(): pass", encoding="UTF-8") |
1800 |
| - result = pytester.runpytest(short_path) |
1801 |
| - assert result.parseoutcomes() == {"passed": 1} |
1802 |
| - |
1803 |
| - def test_ensure_long_path_general(self, tmp_path: Path) -> None: |
1804 |
| - """Sanity check: a normal path to ensure_long_path works on all platforms.""" |
1805 |
| - assert ensure_long_path(tmp_path) == tmp_path |
1806 |
| - assert ensure_long_path(tmp_path / "non-existent") == tmp_path / "non-existent" |
| 1766 | +@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only") |
| 1767 | +def test_collect_short_file_windows(pytester: Pytester) -> None: |
| 1768 | + """Reproducer for #11895: short paths not colleced on Windows.""" |
| 1769 | + short_path = tempfile.mkdtemp() |
| 1770 | + if "~" not in short_path: # pragma: no cover |
| 1771 | + if running_on_ci(): |
| 1772 | + # On CI, we are expecting that under the current GitHub actions configuration, |
| 1773 | + # tempfile.mkdtemp() is producing short paths, so we want to fail to prevent |
| 1774 | + # this from silently changing without us noticing. |
| 1775 | + pytest.fail( |
| 1776 | + f"tempfile.mkdtemp() failed to produce a short path on CI: {short_path}" |
| 1777 | + ) |
| 1778 | + else: |
| 1779 | + # We want to skip failing this test locally in this situation because |
| 1780 | + # depending on the local configuration tempfile.mkdtemp() might not produce a short path: |
| 1781 | + # For example, user might have configured %TEMP% exactly to avoid generating short paths. |
| 1782 | + pytest.skip( |
| 1783 | + f"tempfile.mkdtemp() failed to produce a short path: {short_path}, skipping" |
| 1784 | + ) |
| 1785 | + |
| 1786 | + test_file = Path(short_path).joinpath("test_collect_short_file_windows.py") |
| 1787 | + test_file.write_text("def test(): pass", encoding="UTF-8") |
| 1788 | + result = pytester.runpytest(short_path) |
| 1789 | + assert result.parseoutcomes() == {"passed": 1} |
0 commit comments