File: conftest.py

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (45 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download
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
38
39
40
41
42
43
44
45
# Sharing fixtures
# Ref: https://docs.pytest.org/en/6.2.x/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session

import pytest
from helper import TempRepository


def create_repo(dirname=None):
    repo = TempRepository(dirname)
    repo.create_tmp_file()  # tmp_file_a
    repo.create_tmp_file()  # tmp_file_b
    repo.switch_cwd_under_repo()
    return repo


def init_repo_git_status(repo):
    git = repo.get_repo_git()
    git.add(".")
    git.config("--local", "user.name", "test")
    git.config("--local", "user.email", "test@git-extras.com")
    git.commit("-m", "chore: initial commit")


@pytest.fixture(scope="module")
def temp_repo():
    repo = create_repo()
    init_repo_git_status(repo)
    return repo


@pytest.fixture(scope="module")
def named_temp_repo(request):
    dirname = request.param
    repo = create_repo(dirname)
    init_repo_git_status(repo)
    yield repo
    repo.teardown()


@pytest.fixture(scope="function")
def temp_repo_clean():
    """Create a temporary repository that is reset for each function call."""
    repo = create_repo()
    init_repo_git_status(repo)
    return repo