aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
blob: 38f9bcd70438618a7d0f877d35627a31542d39d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import contextlib
import os
import pathlib
from typing import Iterator


@contextlib.contextmanager
def as_cwd(path: pathlib.Path) -> Iterator[pathlib.Path]:
    old_cwd = os.getcwd()
    os.chdir(path)
    try:
        yield path
    finally:
        os.chdir(old_cwd)