Skip to content

Commit a7838dc

Browse files
thorsten-kleinpdgendt
authored andcommitted
add 'tmp_west_topdir' function for usage in tests
This helper function for tests is added. It temporarily creates a west topdir for the duration of the `with` block by creating a .west directory at given path. The diectory is removed again when the `with` block exits.
1 parent e3e5efc commit a7838dc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@
6868
#
6969

7070

71+
@contextlib.contextmanager
72+
def tmp_west_topdir(path: str | Path):
73+
"""
74+
Temporarily create a west topdir for the duration of the `with` block by
75+
creating a .west directory at given path. The directory is removed again
76+
when the `with` block exits.
77+
"""
78+
west_dir = Path(path) / '.west'
79+
west_dir.mkdir(parents=True)
80+
try:
81+
yield
82+
finally:
83+
# remove the directory (must be empty)
84+
west_dir.rmdir()
85+
86+
7187
@contextlib.contextmanager
7288
def update_env(env: dict[str, str | None]):
7389
"""

0 commit comments

Comments
 (0)