55import unittest
66from unittest import mock
77
8+ import pytest
9+
810import coveralls .git
911from coveralls .exception import CoverallsException
12+ from coveralls .git import run_command
13+
1014
1115GIT_COMMIT_MSG = 'first commit'
12161519GIT_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+
1830class GitTest (unittest .TestCase ):
1931 @classmethod
2032 def setUpClass (cls ):
@@ -76,6 +88,7 @@ def test_git(self):
7688
7789
7890class 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
145158class 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