Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94370d6

Browse files
committed
be nice about current directory in tests
1 parent 7e74821 commit 94370d6

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

tests/git_test.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11

2+
import contextlib
23
import os
34
import pytest
45

56
from plumbum import local
67
from pre_commit import git
78

8-
@pytest.fixture
9+
10+
11+
@contextlib.contextmanager
12+
def in_dir(dir):
13+
old_path = local.cwd.getpath()
14+
local.cwd.chdir(dir)
15+
try:
16+
yield
17+
finally:
18+
local.cwd.chdir(old_path)
19+
20+
@pytest.yield_fixture
921
def empty_git_dir(tmpdir):
10-
local.cwd.chdir(tmpdir.strpath)
11-
local['git']['init']()
12-
return tmpdir.strpath
22+
with in_dir(tmpdir.strpath):
23+
local['git']['init']()
24+
yield tmpdir.strpath
1325

1426

1527
def test_get_root(empty_git_dir):
1628
assert git.get_root() == empty_git_dir
1729

1830
foo = local.path('foo')
1931
foo.mkdir()
20-
local.cwd.chdir(foo)
2132

22-
assert git.get_root() == empty_git_dir
33+
with in_dir(foo):
34+
assert git.get_root() == empty_git_dir
2335

2436

2537
def test_get_pre_commit_path(empty_git_dir):

0 commit comments

Comments
 (0)