Skip to content

Commit 4d10756

Browse files
committed
Use a distinct keep alive file for each test function
1 parent fa7fb00 commit 4d10756

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

tests/common.py

-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
from pathlib import Path
65
from typing import Any, Final, Protocol
76

87

@@ -17,8 +16,6 @@
1716
YEST_DD: Final = "02"
1817
TODAY: Final = f"{YYYY}-{MM}-{DD}"
1918

20-
keep_alive_file_path = Path("/tmp/zorg_test_keep_alive")
21-
2219

2320
class MainType(Protocol):
2421
"""Type returned by main() fixture."""

tests/conftest.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
from pathlib import Path
109
from typing import TYPE_CHECKING, Any, Iterator
1110

1211
from freezegun import freeze_time
@@ -25,15 +24,10 @@
2524

2625

2726
@fixture
28-
def main(make_config_file: MakeConfigFile, tmp_path: Path) -> c.MainType:
27+
def main(make_config_file: MakeConfigFile) -> c.MainType:
2928
"""Returns a wrapper around zorg's main() function."""
3029

31-
default_zettel_dir = tmp_path / "org"
32-
3330
def inner_main(*args: str, **kwargs: Any) -> int:
34-
kwargs.setdefault("zettel_dir", default_zettel_dir)
35-
kwargs.setdefault("keep_alive_file", c.keep_alive_file_path)
36-
3731
cfg_kwargs = {
3832
k: v if isinstance(v, dict) else str(v)
3933
for (k, v) in kwargs.items()

tests/test_edit_cmd.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@ def test_whenEmptyKeepAliveFileExists_shouldRestartVim(
7070
"""Test that we can use the keep alive file to have zorg re-run vim."""
7171
zettel_dir = tmp_path / "org"
7272

73-
c.keep_alive_file_path.touch()
74-
exit_code = main("--dir", str(zettel_dir), "edit", "foobar.zo")
73+
keep_alive_file = tmp_path / "zorg_keep_alive"
74+
keep_alive_file.touch()
75+
exit_code = main(
76+
"--dir",
77+
str(zettel_dir),
78+
"edit",
79+
"foobar.zo",
80+
keep_alive_file=keep_alive_file,
81+
)
7582

7683
assert exit_code == 0
7784
vim_proc_mock.assert_called_with(
@@ -81,7 +88,7 @@ def test_whenEmptyKeepAliveFileExists_shouldRestartVim(
8188
timeout=None,
8289
)
8390
assert vim_proc_mock.call_count == 2
84-
assert not c.keep_alive_file_path.exists()
91+
assert not keep_alive_file.exists()
8592

8693

8794
def test_whenKeepAliveFileContainsPaths_useThosePathsOnRestart(
@@ -90,8 +97,15 @@ def test_whenKeepAliveFileContainsPaths_useThosePathsOnRestart(
9097
"""Test that we can use the keep alive file to change our vim file args."""
9198
zettel_dir = tmp_path / "org"
9299

93-
c.keep_alive_file_path.write_text("baz.zo buz.zo")
94-
exit_code = main("--dir", str(zettel_dir), "edit", "foobar.zo")
100+
keep_alive_file = tmp_path / "zorg_keep_alive"
101+
keep_alive_file.write_text("baz.zo buz.zo")
102+
exit_code = main(
103+
"--dir",
104+
str(zettel_dir),
105+
"edit",
106+
"foobar.zo",
107+
keep_alive_file=keep_alive_file,
108+
)
95109

96110
assert exit_code == 0
97111
vim_proc_mock.assert_has_calls([
@@ -111,4 +125,4 @@ def test_whenKeepAliveFileContainsPaths_useThosePathsOnRestart(
111125
call().unwrap(),
112126
])
113127
assert vim_proc_mock.call_count == 2
114-
assert not c.keep_alive_file_path.exists()
128+
assert not keep_alive_file.exists()

0 commit comments

Comments
 (0)