Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions splunk_add_on_ucc_modinput_test/functional/pytest_plugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ def pytest_deselected(items: Sequence[Item]) -> None:
return

for item in items:
found_tests_keys = (
dependency_manager.tests.lookup_by_original_function(item._obj)
pytest_funcname, _ = _extract_parametrized_data(item)
selected_test = dependency_manager.find_test(
item._obj, pytest_funcname
)
for test_key in found_tests_keys:
test = dependency_manager.unregister_test(test_key)
msg = "Test deselection:"
msg += f'\n\tdeselected: {"Yes" if test else "No"}'
msg += f"\n\tlookup key: {test_key}"
msg += f'\n\tpath: {test.full_path if test else "not found"}'
msg += f'\n\toriginal path: {test.original_full_path if test else "not found"}'
logger.info(msg)
test = (
dependency_manager.unregister_test(selected_test.key)
if selected_test
else None
)
msg = "Test deselection:"
msg += f'\n\tdeselected: {"Yes" if test else "No"}'
msg += f"\n\tlookup name: {pytest_funcname}"
msg += f'\n\tpath: {test.full_path if test else "not found"}'
msg += f'\n\toriginal path: {test.original_full_path if test else "not found"}'
logger.info(msg)


@pytest.hookimpl
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
import logging

from splunk_add_on_ucc_modinput_test.functional.decorators import (
bootstrap,
forge,
)

logger = logging.getLogger("ucc-modinput-test")


def provide_selected_value(parametrized_value: str) -> dict[str, str]:
logger.info(f"provide_selected_value value={parametrized_value}")
return {"forged_value": parametrized_value}


@pytest.mark.parametrize(
"parametrized_value",
[
pytest.param("selected", marks=pytest.mark.selected),
pytest.param("deselected"),
],
)
@bootstrap(forge(provide_selected_value, scope="function"))
def test_partially_selected_parametrized(
parametrized_value: str,
forged_value: str,
) -> None:
assert forged_value == parametrized_value
13 changes: 13 additions & 0 deletions tests/functional/flow/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def test_parametrized(pytester):
)


def test_partially_selected_parametrized(pytester):
with ScenarioTester(
pytester, "partially_selected_parametrized", "-m", "selected"
) as tester:
tester.result.assert_outcomes(passed=1, deselected=1)
tester.test_log_matcher.fnmatch_lines(
["*provide_selected_value value=selected"]
)
tester.test_log_matcher.no_fnmatch_line(
"*provide_selected_value value=deselected"
)


def test_wrongly_parametrized(pytester):
with ScenarioTester(pytester, "invalid_parameters") as tester:
tester.result.stdout.fnmatch_lines(
Expand Down
Loading