-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
80 lines (62 loc) · 1.86 KB
/
conftest.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from textwrap import dedent
from pathlib import Path
import pytest
from pytest_git import GitRepo
@pytest.fixture(scope="session")
def session_git_repo():
"""Session-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
def write_file(repo, filename, content):
file = repo.workspace / filename
Path(file.parent).mkdir(exist_ok=True)
file.write_text(dedent(content))
def append_file(repo, filename, content):
file = repo.workspace / filename
Path(file.parent).mkdir(exist_ok=True)
with file.open(mode="a") as f:
f.write(dedent(content))
@pytest.fixture(scope="session")
def test_repo(session_git_repo) -> GitRepo:
write_file(
session_git_repo,
"test_a.py",
"""
from helper import call_something
class FatherClass:
def father_method(self):
pass
class TestSomething(FatherClass):
def test_method(self):
global_var = global_var + 1
call_something()
self.father_method()
assert 0/1
def test_func1():
call_something()
assert False
""",
)
write_file(
session_git_repo,
"helper.py",
"""
def call_something():
print('doing')
func1()
def func1():
print('doing A')
""",
)
session_git_repo.run("git add *.py")
session_git_repo.api.index.commit("Initial commit")
yield session_git_repo
@pytest.fixture(scope="function", autouse=True)
def clear_changes(test_repo):
test_repo.run("git stash", capture=True)