Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(git): support running tests outside of gitdir #443

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/git_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import unittest
from unittest import mock

import pytest

import coveralls.git
from coveralls.exception import CoverallsException
from coveralls.git import run_command


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


def in_git_dir() -> bool:
try:
run_command('git', 'rev-parse')
return True
except Exception:
return False


class GitTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -76,6 +88,7 @@ def test_git(self):


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


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

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

@pytest.mark.skipif(not in_git_dir(), reason='requires .git directory')
@mock.patch.dict(
os.environ, {
'GITHUB_ACTIONS': 'true',
Expand Down
Loading