1
|
|
|
import os |
2
|
|
|
import pytest |
3
|
|
|
import sys |
4
|
|
|
|
5
|
|
|
# The following addition to sys.path is needed to find imports |
6
|
|
|
# like 'from test.test_plugins import BasicPlugin' |
7
|
|
|
# Normally the test path is not part of sys.path |
8
|
|
|
sys.path.append("/".join([os.path.dirname(os.path.abspath(__file__)), ".."])) |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
@pytest.fixture |
12
|
|
|
def test_apps(monkeypatch): |
13
|
|
|
monkeypatch.syspath_prepend( |
14
|
|
|
os.path.abspath(os.path.join( |
15
|
|
|
os.path.dirname(__file__), 'test_apps')) |
16
|
|
|
) |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
@pytest.fixture |
20
|
|
|
def test_plugins(monkeypatch): |
21
|
|
|
monkeypatch.syspath_prepend( |
22
|
|
|
os.path.abspath(os.path.join( |
23
|
|
|
os.path.dirname(__file__), 'test_plugins')) |
24
|
|
|
) |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
@pytest.fixture |
28
|
|
|
def basicApp(): |
29
|
|
|
""" |
30
|
|
|
Loads a basic groundwork application and returns it. |
31
|
|
|
|
32
|
|
|
See tests/test_apps/basic_app for implementation details |
33
|
|
|
:return: app |
34
|
|
|
""" |
35
|
|
|
from groundwork import App |
36
|
|
|
from tests.test_plugins import BasicPlugin, CommandPlugin, DocumentPlugin |
37
|
|
|
from tests.test_plugins import SharedObjectPlugin, RecipePlugin, ThreadPlugin |
38
|
|
|
|
39
|
|
|
app = App(plugins=[BasicPlugin, CommandPlugin, DocumentPlugin, SharedObjectPlugin, |
40
|
|
|
RecipePlugin, ThreadPlugin], strict=True) |
41
|
|
|
app.plugins.activate(["BasicPlugin", "CommandPlugin", "DocumentPlugin", "SharedObjectPlugin", |
42
|
|
|
"RecipePlugin", "ThreadPlugin"]) |
43
|
|
|
return app |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
@pytest.fixture |
47
|
|
|
def emptyApp(): |
48
|
|
|
""" |
49
|
|
|
Loads an empty groundwork application and returns it. |
50
|
|
|
:return: app |
51
|
|
|
""" |
52
|
|
|
from groundwork import App |
53
|
|
|
app = App(plugins=[], strict=True) |
54
|
|
|
return app |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
@pytest.fixture |
58
|
|
|
def EmptyPlugin(): |
59
|
|
|
""" |
60
|
|
|
:return: empty plugin class |
61
|
|
|
""" |
62
|
|
|
from tests.test_plugins.empty_plugin import EmptyPlugin |
63
|
|
|
return EmptyPlugin |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
@pytest.fixture |
67
|
|
|
def EmptyCommandPlugin(): |
68
|
|
|
""" |
69
|
|
|
:return: empty command plugin class |
70
|
|
|
""" |
71
|
|
|
from tests.test_plugins.empty_command_plugin import EmptyCommandPlugin |
72
|
|
|
return EmptyCommandPlugin |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
@pytest.fixture |
76
|
|
|
def EmptyDocumentPlugin(): |
77
|
|
|
""" |
78
|
|
|
:return: empty document plugin class |
79
|
|
|
""" |
80
|
|
|
from tests.test_plugins.empty_document_plugin import EmptyDocumentPlugin |
81
|
|
|
return EmptyDocumentPlugin |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
@pytest.fixture |
85
|
|
|
def EmptySharedObjectPlugin(): |
86
|
|
|
""" |
87
|
|
|
:return: empty shared object plugin class |
88
|
|
|
""" |
89
|
|
|
from tests.test_plugins.empty_shared_object_plugin import EmptySharedObjectPlugin |
90
|
|
|
return EmptySharedObjectPlugin |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
@pytest.fixture |
94
|
|
|
def BasicPlugin(): |
95
|
|
|
""" |
96
|
|
|
:return: basic plugin class |
97
|
|
|
""" |
98
|
|
|
from tests.test_plugins.basic_plugin import BasicPlugin |
99
|
|
|
return BasicPlugin |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
@pytest.fixture |
103
|
|
|
def CommandPlugin(): |
104
|
|
|
""" |
105
|
|
|
:return: command plugin class |
106
|
|
|
""" |
107
|
|
|
from tests.test_plugins.commands_plugin import CommandPlugin |
108
|
|
|
return CommandPlugin |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
@pytest.fixture |
112
|
|
|
def DocumentPlugin(): |
113
|
|
|
""" |
114
|
|
|
:return: document plugin class |
115
|
|
|
""" |
116
|
|
|
from tests.test_plugins.documentations_plugin import DocumentPlugin |
117
|
|
|
return DocumentPlugin |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
@pytest.fixture |
121
|
|
|
def ThreadPlugin(): |
122
|
|
|
""" |
123
|
|
|
:return: thread plugin class |
124
|
|
|
""" |
125
|
|
|
from tests.test_plugins.threads_plugin import ThreadPlugin |
126
|
|
|
return ThreadPlugin |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
# See http://docs.pytest.org/en/latest/example/simple.html#incremental-testing-test-steps |
130
|
|
|
def pytest_runtest_makereport(item, call): |
131
|
|
|
if "incremental" in item.keywords: |
132
|
|
|
if call.excinfo is not None: |
133
|
|
|
parent = item.parent |
134
|
|
|
parent._previousfailed = item |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
# See http://docs.pytest.org/en/latest/example/simple.html#incremental-testing-test-steps |
138
|
|
|
def pytest_runtest_setup(item): |
139
|
|
|
if "incremental" in item.keywords: |
140
|
|
|
previousfailed = getattr(item.parent, "_previousfailed", None) |
141
|
|
|
if previousfailed is not None: |
142
|
|
|
pytest.xfail("previous test failed (%s)" % previousfailed.name) |
143
|
|
|
|