Skip to content

Commit c5b0fc6

Browse files
committed
Fix pager test pollution for parallel execution
Use pytest's ``tmp_path`` fixture instead of a shared ``Path(tempdir) / "pager_out.txt"`` path. The ``tempfile.tempdir`` module global defaults to ``None``, so ``Path(None)`` resolves to the current directory, causing all parallel workers to race on the same file.
1 parent af5facf commit c5b0fc6

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

tests/test_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from fractions import Fraction
1010
from functools import partial
1111
from io import StringIO
12-
from pathlib import Path
13-
from tempfile import tempdir
1412
from unittest.mock import patch
1513

1614
import pytest
@@ -379,7 +377,7 @@ def _test_simulate_keyboard_interrupt(file=None):
379377
),
380378
],
381379
)
382-
def test_echo_via_pager(monkeypatch, capfd, pager_cmd, test):
380+
def test_echo_via_pager(monkeypatch, capfd, pager_cmd, test, tmp_path):
383381
monkeypatch.setitem(os.environ, "PAGER", pager_cmd)
384382
monkeypatch.setattr(click._termui_impl, "isatty", lambda x: True)
385383

@@ -391,8 +389,7 @@ def test_echo_via_pager(monkeypatch, capfd, pager_cmd, test):
391389

392390
check_raise = pytest.raises(expected_error) if expected_error else nullcontext()
393391

394-
pager_out_tmp = Path(tempdir) / "pager_out.txt"
395-
pager_out_tmp.unlink(missing_ok=True)
392+
pager_out_tmp = tmp_path / "pager_out.txt"
396393
with pager_out_tmp.open("w") as f:
397394
force_subprocess_stdout = patch.object(
398395
subprocess,

0 commit comments

Comments
 (0)