@@ -206,17 +206,16 @@ def media_path(test_config: dict) -> str:
206206
207207
208208@pytest .fixture (scope = "session" )
209- def log_path_dir (test_config : dict ) -> str :
209+ def log_path_dir (test_config : dict , pytestconfig ) :
210210 """
211211 Creates and returns the main log directory path for the test session.
212212
213213 The directory is created under the path provided by get_log_folder_path.
214214 If keep_logs is False, the existing log directory is removed before creating a new one.
215215
216216 :param test_config: Dictionary containing test configuration.
217- :return: Path to the main log directory for the session.
218- :rtype: str
219217 """
218+ add_logging_level ("TESTCMD" , TESTCMD_LVL )
220219 keep_logs = test_config .get ("keep_logs" , True )
221220 timestamp = datetime .now ().strftime ("%Y%m%d_%H%M%S" )
222221 log_dir_name = f"log_{ timestamp } "
@@ -226,7 +225,10 @@ def log_path_dir(test_config: dict) -> str:
226225 shutil .rmtree (log_dir )
227226 log_dir = Path (log_dir , log_dir_name )
228227 log_dir .mkdir (parents = True , exist_ok = True )
229- return str (log_dir )
228+ yield str (log_dir )
229+ pytest_log = Path (pytestconfig .inicfg ["log_file" ])
230+ shutil .copy (str (pytest_log ), log_dir / pytest_log .name )
231+ csv_write_report (str (log_dir / "report.csv" ))
230232
231233
232234def sanitize_name (test_name ):
@@ -822,59 +824,24 @@ def log_interface_driver_info(hosts: dict[str, Host]) -> None:
822824 )
823825
824826
825- @pytest .fixture (scope = "session" , autouse = True )
826- def log_session ():
827- add_logging_level ("TESTCMD" , TESTCMD_LVL )
828-
829- today = datetime .today ()
830- folder = today .strftime ("%Y-%m-%dT%H:%M:%S" )
831- path = os .path .join (LOG_FOLDER , folder )
832- path_symlink = os .path .join (LOG_FOLDER , "latest" )
833- try :
834- os .remove (path_symlink )
835- except FileNotFoundError :
836- pass
837- os .makedirs (path , exist_ok = True )
838- os .symlink (folder , path_symlink )
839- yield
840- shutil .copy ("pytest.log" , f"{ LOG_FOLDER } /latest/pytest.log" )
841- csv_write_report (f"{ LOG_FOLDER } /latest/report.csv" )
842-
843827@pytest .fixture (scope = "function" , autouse = True )
844828def log_case (request , caplog : pytest .LogCaptureFixture ):
845829 case_id = request .node .nodeid
846- case_folder = os .path .dirname (case_id )
847- os .makedirs (os .path .join (LOG_FOLDER , "latest" , case_folder ), exist_ok = True )
848- logfile = os .path .join (LOG_FOLDER , "latest" , f"{ case_id } .log" )
849- fh = logging .FileHandler (logfile )
850- formatter = request .session .config .pluginmanager .get_plugin (
851- "logging-plugin"
852- ).formatter
853- format = AmberLogFormatter (formatter )
854- fh .setFormatter (format )
855- fh .setLevel (logging .DEBUG )
856- logger = logging .getLogger ()
857- logger .addHandler (fh )
858830 yield
859831 report = request .node .stash [phase_report_key ]
860832 if report ["setup" ].failed :
861833 logging .log (level = TEST_FAIL , msg = f"Setup failed for { case_id } " )
862- os .chmod (logfile , 0o4755 )
863834 result = "Fail"
864835 elif ("call" not in report ) or report ["call" ].failed :
865836 logging .log (level = TEST_FAIL , msg = f"Test failed for { case_id } " )
866- os .chmod (logfile , 0o4755 )
867837 result = "Fail"
868838 elif report ["call" ].passed :
869839 logging .log (level = TEST_PASS , msg = f"Test passed for { case_id } " )
870- os .chmod (logfile , 0o755 )
871840 result = "Pass"
872841 else :
873842 logging .log (level = TEST_INFO , msg = f"Test skipped for { case_id } " )
874843 result = "Skip"
875844
876- logger .removeHandler (fh )
877-
878845 commands = []
879846 for record in caplog .get_records ("call" ):
880847 if record .levelno == TESTCMD_LVL :
@@ -887,22 +854,3 @@ def log_case(request, caplog: pytest.LogCaptureFixture):
887854 issue = "n/a" ,
888855 result_note = "n/a" ,
889856 )
890-
891-
892- @pytest .fixture (scope = "session" )
893- def compliance_report (request , log_session , test_config ):
894- """
895- This function is used for compliance check and report.
896- """
897- # TODO: Implement compliance check logic. When tcpdump pcap is enabled, at the end of the test session all pcaps
898- # shall be send into EBU list.
899- # Pcaps shall be stored in the ramdisk, and then moved to the compliance
900- # folder or send into EBU list after each test finished and remove it from the ramdisk.
901- # Compliance report generation logic goes here after yield. Or in another class / function but triggered here.
902- # AFAIK names of pcaps contains test name so it can be matched with result of each test like in code below.
903- yield
904- if test_config .get ("compliance" , False ):
905- logging .info ("Compliance mode enabled, updating compliance results" )
906- for item in request .session .items :
907- test_case = item .nodeid
908- update_compliance_result (test_case , "Fail" )
0 commit comments