Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 1c06284

Browse files
committed
refactor(tests) Use marker to skip tests that depend on a git repo
1 parent 7a3fab9 commit 1c06284

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ def mytest_model():
6161

6262
@pytest.fixture(scope='function', autouse=False)
6363
def user_instance(request, admin_user):
64-
request.cls.user = admin_user
64+
request.cls.user = admin_user
65+
66+
67+
@pytest.fixture(autouse=True)
68+
def has_git_requirements(request, project_root):
69+
if request.node.get_marker('has_git_requirements'):
70+
if not os.path.exists(os.path.join(project_root, '.git', 'refs', 'heads', 'master')):
71+
pytest.skip('skipped test as project is not a git repo')

tests/versioning/tests.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
import pytest
55
import subprocess
66

7-
from conftest import project_root
87
from raven.utils.compat import string_types
98
from raven.versioning import fetch_git_sha, fetch_package_version
109

1110

12-
def has_git_requirements(project_root):
13-
return os.path.exists(os.path.join(project_root, '.git', 'refs', 'heads', 'master'))
14-
15-
1611
# Python 2.6 does not contain subprocess.check_output
1712
def check_output(cmd, **kwargs):
1813
return subprocess.Popen(
@@ -22,8 +17,7 @@ def check_output(cmd, **kwargs):
2217
).communicate()[0]
2318

2419

25-
@pytest.mark.skipif(not has_git_requirements(project_root()),
26-
reason='unable to detect git repository')
20+
@pytest.mark.has_git_requirements
2721
def test_fetch_git_sha(project_root):
2822
result = fetch_git_sha(project_root)
2923
assert result is not None

0 commit comments

Comments
 (0)