Skip to content

Commit dfde610

Browse files
fix: remove-pytest_exception_interact hook (#881)
This PR reverts partially changes introduced in this PR: 7cc8880#diff-2699a131e5dfd55b20327a39ec213c806ee847e17b6666faf0a01fe850448f47L558 This change is necessary, since exiting pytest while getting `Exception` disturbed other tests (fr example UI test https://splunk.atlassian.net/browse/ADDON-72764). Instead of that HEC token is validated by ingesting simple event with it (implemented in this PR: #877).
1 parent 7f3787d commit dfde610

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

.github/workflows/build-test-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ jobs:
129129
path: |
130130
test-results-${{ matrix.splunk.version }}
131131
132+
132133
test-splunk-matrix:
133134
needs:
134135
- meta
@@ -149,7 +150,6 @@ jobs:
149150
"splunk_app_cim_broken",
150151
"splunk_fiction_indextime",
151152
"splunk_fiction_indextime_broken",
152-
"splunk_fiction_indextime_wrong_hec_token",
153153
"splunk_setup_fixture",
154154
"splunk_app_req",
155155
"splunk_app_req_broken",

pytest_splunk_addon/plugin.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
test_generator = None
2828

29-
EXC_MAP = [Exception]
30-
3129

3230
def pytest_configure(config):
3331
"""
@@ -122,7 +120,6 @@ def pytest_sessionstart(session):
122120
SampleXdistGenerator.tokenized_event_source = session.config.getoption(
123121
"tokenized_event_source"
124122
).lower()
125-
session.__exc_limits = EXC_MAP
126123
if (
127124
SampleXdistGenerator.tokenized_event_source == "store_new"
128125
and session.config.getoption("ingest_events").lower()
@@ -212,14 +209,3 @@ def init_pytest_splunk_addon_logger():
212209

213210
init_pytest_splunk_addon_logger()
214211
LOGGER = logging.getLogger("pytest-splunk-addon")
215-
216-
217-
def pytest_exception_interact(node, call, report):
218-
"""
219-
Hook called when an exception is raised during a test.
220-
If the number of occurrences for a specific exception exceeds the limit in session.__exc_limits, pytest exits
221-
https://docs.pytest.org/en/stable/reference/reference.html#pytest.hookspec.pytest_exception_interact
222-
"""
223-
if call.excinfo.type in node.session.__exc_limits:
224-
# pytest exits only for exceptions defined in EXC_MAP
225-
pytest.exit(f"Exiting pytest due to: {call.excinfo.type}")

pytest_splunk_addon/splunk.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def is_responsive_hec(request, splunk):
979979
f'{request.config.getoption("splunk_hec_scheme")}://{splunk["forwarder_host"]}:{splunk["port_hec"]}/services/collector/health/1.0',
980980
verify=False,
981981
)
982-
LOGGER.debug("Status code: {}".format(response.status_code))
982+
LOGGER.debug("Status code: %d", response.status_code)
983983
if response.status_code in (200, 201):
984984
LOGGER.info("Splunk HEC is responsive.")
985985
return True
@@ -1040,7 +1040,8 @@ def is_valid_hec(request, splunk):
10401040
data={"event": "test_hec", "sourcetype": "hec_token_test"},
10411041
verify=False,
10421042
)
1043-
LOGGER.debug("Status code: {}".format(response.status_code))
1043+
LOGGER.debug("Status code: %d", response.status_code)
1044+
10441045
if response.status_code == 200:
10451046
LOGGER.info("Splunk HEC is valid.")
10461047
else:

tests/e2e/test_splunk_addon.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ def empty_method():
169169
assert result.ret == 0
170170

171171

172-
@pytest.mark.docker
173172
@pytest.mark.splunk_fiction_indextime_wrong_hec_token
173+
@pytest.mark.external
174174
def test_splunk_fiction_indextime_wrong_hec_token(testdir, request):
175175
"""Make sure that pytest accepts our fixture."""
176176

@@ -205,17 +205,20 @@ def empty_method():
205205
# run pytest with the following cmd args
206206
result = testdir.runpytest(
207207
f"--splunk-version={request.config.getoption('splunk_version')}",
208-
"--splunk-type=docker",
208+
"--splunk-type=external",
209+
"--splunk-host=splunk",
210+
"--splunk-port=8089",
211+
"--splunk-forwarder-host=splunk",
212+
"--splunk-hec-token=8b741d03-43e9-4164-908b-e09102327d22",
209213
"-v",
210214
"--search-interval=0",
211215
"--search-retry=0",
212216
"--splunk-data-generator=tests/addons/TA_fiction_indextime/default",
213217
"--search-index=*,_internal",
214218
)
215219

216-
result.assert_outcomes(errors=1, passed=0, failed=0, xfailed=0)
217220
result.stdout.fnmatch_lines(
218-
"!!!!!! _pytest.outcomes.Exit: Exiting pytest due to: <class 'Exception'> !!!!!!!"
221+
"*_pytest.outcomes.Exit: Exiting pytest due to invalid HEC token value."
219222
)
220223

221224
assert result.ret != 0

0 commit comments

Comments
 (0)