11import logging
22import pytest
3- import sys
3+ from . standard_lib . sample_generation . sample_xdist_generator import SampleXdistGenerator
44import traceback
55from .standard_lib import AppTestGenerator
66from .standard_lib .cim_compliance import CIMReportPlugin
@@ -78,11 +78,32 @@ def pytest_unconfigure(config):
7878 del config ._markdown
7979 config .pluginmanager .unregister (markdown )
8080
81+ def pytest_sessionstart (session ):
82+
83+ SampleXdistGenerator .event_path = session .config .getoption ("event_path" )
84+ SampleXdistGenerator .event_stored = False
85+ SampleXdistGenerator .tokenized_event_source = session .config .getoption ("tokenized_event_source" ).lower ()
86+ # For scenario (store_new, False, False) get_samples from SampleXdistGenerator will not be invoked
87+ # Because all teh tests are skipped, So event.pickle file will not be generated
88+ # For this scenarios tokenized_event is generated here
89+ if (
90+ SampleXdistGenerator .tokenized_event_source == "store_new"
91+ and session .config .getoption ("ingest_events" ).lower () in ["no" , "n" , "false" , "f" ]
92+ and session .config .getoption ("execute_test" ).lower () in ["no" , "n" , "false" , "f" ]
93+ ):
94+ app_path = session .config .getoption ("splunk_app" )
95+ config_path = session .config .getoption ("splunk_data_generator" )
96+ store_events = session .config .getoption ("store_events" )
97+ sample_generator = SampleXdistGenerator (app_path , config_path )
98+ sample_generator .get_samples (store_events )
99+
81100
82101def pytest_generate_tests (metafunc ):
83102 """
84103 Parse the fixture dynamically.
85104 """
105+ if metafunc .config .getoption ("execute_test" ).lower () in ["no" ,"n" ,"false" ,"f" ]:
106+ return
86107 global test_generator
87108 for fixture in metafunc .fixturenames :
88109 if fixture .startswith ("splunk_searchtime" ) or fixture .startswith (
@@ -111,6 +132,13 @@ def pytest_generate_tests(metafunc):
111132 f"\n Logs:\n { log_message } "
112133 )
113134
135+ def pytest_collection_modifyitems (config , items ):
136+ ingest_events_flag = config .getoption ("ingest_events" )
137+ is_ingest_false = ingest_events_flag .lower () in ["no" ,"n" ,"false" ,"f" ]
138+ execute_test_flag = config .getoption ("execute_test" )
139+ if execute_test_flag .lower () in ["no" ,"n" ,"false" ,"f" ]:
140+ for item in items .copy ():
141+ item .add_marker (pytest .mark .skipif (item .name != 'test_events_with_untokenised_values' or is_ingest_false , reason = f'--execute-test={ execute_test_flag } provided' ))
114142
115143def init_pytest_splunk_addon_logger ():
116144 """
@@ -128,6 +156,5 @@ def init_pytest_splunk_addon_logger():
128156 logger .setLevel (logging .INFO )
129157 return logger
130158
131-
132159init_pytest_splunk_addon_logger ()
133160LOGGER = logging .getLogger ("pytest-splunk-addon" )
0 commit comments