-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathpytest_git.py
More file actions
37 lines (30 loc) · 923 Bytes
/
pytest_git.py
File metadata and controls
37 lines (30 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
""" Repository fixtures
"""
import pytest
from pytest_shutil.workspace import Workspace
from git import Repo
@pytest.yield_fixture
def git_repo(request):
""" Function-scoped fixture to create a new git repo in a temporary workspace.
Attributes
----------
uri (str) : Repository URI
api (`git.Repo`) : Git Repo object for this repository
.. also inherits all attributes from the `workspace` fixture
"""
with GitRepo() as repo:
yield repo
class GitRepo(Workspace):
"""
Creates an empty Git repository in a temporary workspace.
Cleans up on exit.
Attributes
----------
uri : `str`
repository base uri
api : `git.Repo` handle to the repository
"""
def __init__(self):
super(GitRepo, self).__init__()
self.api = Repo.init(self.workspace)
self.uri = "file://%s" % self.workspace