Skip to content

Commit 5456ed2

Browse files
committed
Mark tests as app
1 parent 8276be4 commit 5456ed2

File tree

7 files changed

+39
-58
lines changed

7 files changed

+39
-58
lines changed

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[pytest]
22
markers =
3+
app: requires sdk-app-collection
34
smoke: essential smoke tests
45

56
junit_family =

tests/test_index.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,8 @@ def test_submit_via_attach_with_multiple_cookie_headers(self):
170170
cn.close()
171171
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)
172172

173+
@pytest.mark.app
173174
def test_upload(self):
174-
if not self.app_collection_installed():
175-
print("Test requires sdk-app-collection. Skipping.")
176-
return
177175
self.install_app_from_collection("file_to_upload")
178176

179177
event_count = int(self.index['totalEventCount'])

tests/test_input.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import splunklib.client as client
3030

31+
import pytest
32+
3133

3234
def highest_port(service, base_port, *kinds):
3335
"""Find the first port >= base_port not in use by any input in kinds."""
@@ -164,10 +166,8 @@ def test_inputs_list_on_one_kind_with_search(self):
164166
found = [x.name for x in self.service.inputs.list('monitor', search=search)]
165167
self.assertEqual(expected, found)
166168

169+
@pytest.mark.app
167170
def test_oneshot(self):
168-
if not self.app_collection_installed():
169-
print("Test requires sdk-app-collection. Skipping.")
170-
return
171171
self.install_app_from_collection('file_to_upload')
172172

173173
index_name = testlib.tmpname()
@@ -225,25 +225,19 @@ def test_list(self):
225225
for input in input_list:
226226
self.assertTrue(input.name is not None)
227227

228+
@pytest.mark.app
228229
def test_lists_modular_inputs(self):
229-
if self.service.splunk_version[0] < 5:
230-
print("Modular inputs don't exist prior to Splunk 5.0. Skipping.")
231-
return
232-
elif not self.app_collection_installed():
233-
print("Test requires sdk-app-collection. Skipping.")
234-
return
235-
else:
236-
# Install modular inputs to list, and restart
237-
# so they'll show up.
238-
self.install_app_from_collection("modular-inputs")
239-
self.uncheckedRestartSplunk()
240-
241-
inputs = self.service.inputs
242-
if ('abcd','test2') not in inputs:
243-
inputs.create('abcd', 'test2', field1='boris')
244-
245-
input = inputs['abcd', 'test2']
246-
self.assertEqual(input.field1, 'boris')
230+
# Install modular inputs to list, and restart
231+
# so they'll show up.
232+
self.install_app_from_collection("modular-inputs")
233+
self.uncheckedRestartSplunk()
234+
235+
inputs = self.service.inputs
236+
if ('abcd','test2') not in inputs:
237+
inputs.create('abcd', 'test2', field1='boris')
238+
239+
input = inputs['abcd', 'test2']
240+
self.assertEqual(input.field1, 'boris')
247241

248242
def test_create(self):
249243
inputs = self.service.inputs

tests/test_job.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
from splunklib.binding import _log_duration, HTTPError
3636

37+
import pytest
38+
3739
# TODO: Determine if we should be importing ExpatError if ParseError is not avaialble (e.g., on Python 2.6)
3840
# There's code below that now catches SyntaxError instead of ParseError. Should we be catching ExpathError instead?
3941

@@ -214,10 +216,8 @@ def tearDown(self):
214216
self.job.cancel()
215217
self.assertEventuallyTrue(lambda: self.job.sid not in self.service.jobs)
216218

219+
@pytest.mark.app
217220
def test_enable_preview(self):
218-
if not self.app_collection_installed():
219-
print("Test requires sdk-app-collection. Skipping.")
220-
return
221221
self.install_app_from_collection("sleep_command")
222222
sleep_duration = 100
223223
self.query = "search index=_internal | sleep %d" % sleep_duration
@@ -240,10 +240,8 @@ def is_preview_enabled():
240240
self.assertEventuallyTrue(is_preview_enabled)
241241
return
242242

243+
@pytest.mark.app
243244
def test_setpriority(self):
244-
if not self.app_collection_installed():
245-
print("Test requires sdk-app-collection. Skipping.")
246-
return
247245
self.install_app_from_collection("sleep_command")
248246
sleep_duration = 100
249247
self.query = "search index=_internal | sleep %s" % sleep_duration

tests/test_modular_input.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,21 @@ def setUp(self):
3030
super(ModularInputKindTestCase, self).setUp()
3131
self.uncheckedRestartSplunk()
3232

33+
@pytest.mark.app
3334
def test_lists_modular_inputs(self):
34-
if self.service.splunk_version[0] < 5:
35-
print("Modular inputs don't exist prior to Splunk 5.0. Skipping.")
36-
return
37-
elif not self.app_collection_installed():
38-
print("Test requires sdk-app-collection. Skipping.")
39-
return
40-
else:
41-
# Install modular inputs to list, and restart
42-
# so they'll show up.
43-
self.install_app_from_collection("modular-inputs")
44-
self.uncheckedRestartSplunk()
35+
# Install modular inputs to list, and restart
36+
# so they'll show up.
37+
self.install_app_from_collection("modular-inputs")
38+
self.uncheckedRestartSplunk()
4539

46-
inputs = self.service.inputs
47-
if ('abcd','test2') not in inputs:
48-
inputs.create('abcd', 'test2', field1='boris')
40+
inputs = self.service.inputs
41+
if ('abcd','test2') not in inputs:
42+
inputs.create('abcd', 'test2', field1='boris')
4943

50-
input = inputs['abcd', 'test2']
51-
self.assertEqual(input.field1, 'boris')
52-
for m in self.service.modular_input_kinds:
53-
self.check_modular_input_kind(m)
44+
input = inputs['abcd', 'test2']
45+
self.assertEqual(input.field1, 'boris')
46+
for m in self.service.modular_input_kinds:
47+
self.check_modular_input_kind(m)
5448

5549
def check_modular_input_kind(self, m):
5650
print(m.name)

tests/test_modular_input_kinds.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
import unittest2 as unittest
2424
import splunklib.client as client
2525

26+
import pytest
27+
2628
class ModularInputKindTestCase(testlib.SDKTestCase):
2729
def setUp(self):
2830
super(ModularInputKindTestCase, self).setUp()
2931
self.uncheckedRestartSplunk()
3032

33+
@pytest.mark.app
3134
def test_list_arguments(self):
32-
if not self.app_collection_installed():
33-
print("Test requires sdk-app-collection. Skipping.")
34-
return
3535
self.install_app_from_collection("modular-inputs")
3636

3737
if self.service.splunk_version[0] < 5:
@@ -47,10 +47,8 @@ def test_list_arguments(self):
4747

4848
self.assertEqual(expected_args, found_args)
4949

50+
@pytest.mark.app
5051
def test_update_raises_exception(self):
51-
if not self.app_collection_installed():
52-
print("Test requires sdk-app-collection. Skipping.")
53-
return
5452
self.install_app_from_collection("modular-inputs")
5553

5654
if self.service.splunk_version[0] < 5:
@@ -68,10 +66,8 @@ def check_modular_input_kind(self, m):
6866
self.assertEqual('test2', m['title'])
6967
self.assertEqual('simple', m['streaming_mode'])
7068

69+
@pytest.mark.app
7170
def test_list_modular_inputs(self):
72-
if not self.app_collection_installed():
73-
print("Test requires sdk-app-collection. Skipping.")
74-
return
7571
self.install_app_from_collection("modular-inputs")
7672

7773
if self.service.splunk_version[0] < 5:

tests/testlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def assertEventuallyTrue(self, predicate, timeout=30, pause_time=0.5,
9797
logging.debug("wait finished after %s seconds", datetime.now()-start)
9898

9999
def check_content(self, entity, **kwargs):
100-
for k, v in six.iteritems(kwargs):
100+
for k, v in six.iteritems(kwargs):
101101
self.assertEqual(entity[k], str(v))
102102

103103
def check_entity(self, entity):

0 commit comments

Comments
 (0)