Skip to content

Commit b566fc3

Browse files
authored
test(git): support running tests outside of gitdir (#443)
1 parent f41dca5 commit b566fc3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/git_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
import unittest
66
from unittest import mock
77

8+
import pytest
9+
810
import coveralls.git
911
from coveralls.exception import CoverallsException
12+
from coveralls.git import run_command
13+
1014

1115
GIT_COMMIT_MSG = 'first commit'
1216
GIT_EMAIL = '[email protected]'
@@ -15,6 +19,14 @@
1519
GIT_URL = 'https://github.com/username/Hello-World.git'
1620

1721

22+
def in_git_dir() -> bool:
23+
try:
24+
run_command('git', 'rev-parse')
25+
return True
26+
except Exception:
27+
return False
28+
29+
1830
class GitTest(unittest.TestCase):
1931
@classmethod
2032
def setUpClass(cls):
@@ -76,6 +88,7 @@ def test_git(self):
7688

7789

7890
class GitLogTest(GitTest):
91+
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory')
7992
def test_gitlog(self):
8093
git_info = coveralls.git.gitlog('%H')
8194
assert re.match(r'^[a-f0-9]{40}$', git_info)
@@ -143,6 +156,7 @@ def test_gitinfo_not_a_git_repo(self):
143156

144157

145158
class GitInfoOverridesTest(unittest.TestCase):
159+
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory')
146160
@mock.patch.dict(
147161
os.environ, {
148162
'GITHUB_ACTIONS': 'true',
@@ -155,6 +169,7 @@ def test_gitinfo_github_pr(self):
155169
git_info = coveralls.git.git_info()
156170
assert git_info['git']['branch'] == 'fixup-branch'
157171

172+
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory')
158173
@mock.patch.dict(
159174
os.environ, {
160175
'GITHUB_ACTIONS': 'true',
@@ -167,6 +182,7 @@ def test_gitinfo_github_branch(self):
167182
git_info = coveralls.git.git_info()
168183
assert git_info['git']['branch'] == 'master'
169184

185+
@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory')
170186
@mock.patch.dict(
171187
os.environ, {
172188
'GITHUB_ACTIONS': 'true',

0 commit comments

Comments
 (0)