@@ -596,6 +596,14 @@ def _log_cli_enabled(self):
596
596
597
597
return True
598
598
599
+ @pytest .hookimpl (hookwrapper = True , tryfirst = True )
600
+ def pytest_sessionstart (self ):
601
+ self .log_cli_handler .set_when ("sessionstart" )
602
+
603
+ with catching_logs (self .log_cli_handler , level = self .log_cli_level ):
604
+ with catching_logs (self .log_file_handler , level = self .log_file_level ):
605
+ yield
606
+
599
607
@pytest .hookimpl (hookwrapper = True , tryfirst = True )
600
608
def pytest_collection (self ) -> Generator [None , None , None ]:
601
609
self .log_cli_handler .set_when ("collection" )
@@ -604,6 +612,31 @@ def pytest_collection(self) -> Generator[None, None, None]:
604
612
with catching_logs (self .log_file_handler , level = self .log_file_level ):
605
613
yield
606
614
615
+ @pytest .hookimpl (hookwrapper = True )
616
+ def pytest_runtestloop (self , session ):
617
+ """Runs all collected test items."""
618
+
619
+ if session .config .option .collectonly :
620
+ yield
621
+ return
622
+
623
+ if self ._log_cli_enabled () and self ._config .getoption ("verbose" ) < 1 :
624
+ # setting verbose flag is needed to avoid messy test progress output
625
+ self ._config .option .verbose = 1
626
+
627
+ with catching_logs (self .log_cli_handler , level = self .log_cli_level ):
628
+ with catching_logs (self .log_file_handler , level = self .log_file_level ):
629
+ yield # run all the tests
630
+
631
+ @pytest .hookimpl
632
+ def pytest_runtest_logstart (self ):
633
+ self .log_cli_handler .reset ()
634
+ self .log_cli_handler .set_when ("start" )
635
+
636
+ @pytest .hookimpl
637
+ def pytest_runtest_logreport (self ):
638
+ self .log_cli_handler .set_when ("logreport" )
639
+
607
640
def _runtest_for (self , item : nodes .Item , when : str ) -> Generator [None , None , None ]:
608
641
"""Implements the internals of pytest_runtest_xxx() hook."""
609
642
log_handler = LogCaptureHandler ()
@@ -639,19 +672,10 @@ def pytest_runtest_teardown(self, item):
639
672
del item ._store [catch_log_handlers_key ]
640
673
del item ._store [catch_log_handler_key ]
641
674
642
- @pytest .hookimpl
643
- def pytest_runtest_logstart (self ):
644
- self .log_cli_handler .reset ()
645
- self .log_cli_handler .set_when ("start" )
646
-
647
675
@pytest .hookimpl
648
676
def pytest_runtest_logfinish (self ):
649
677
self .log_cli_handler .set_when ("finish" )
650
678
651
- @pytest .hookimpl
652
- def pytest_runtest_logreport (self ):
653
- self .log_cli_handler .set_when ("logreport" )
654
-
655
679
@pytest .hookimpl (hookwrapper = True , tryfirst = True )
656
680
def pytest_sessionfinish (self ):
657
681
self .log_cli_handler .set_when ("sessionfinish" )
@@ -660,30 +684,6 @@ def pytest_sessionfinish(self):
660
684
with catching_logs (self .log_file_handler , level = self .log_file_level ):
661
685
yield
662
686
663
- @pytest .hookimpl (hookwrapper = True , tryfirst = True )
664
- def pytest_sessionstart (self ):
665
- self .log_cli_handler .set_when ("sessionstart" )
666
-
667
- with catching_logs (self .log_cli_handler , level = self .log_cli_level ):
668
- with catching_logs (self .log_file_handler , level = self .log_file_level ):
669
- yield
670
-
671
- @pytest .hookimpl (hookwrapper = True )
672
- def pytest_runtestloop (self , session ):
673
- """Runs all collected test items."""
674
-
675
- if session .config .option .collectonly :
676
- yield
677
- return
678
-
679
- if self ._log_cli_enabled () and self ._config .getoption ("verbose" ) < 1 :
680
- # setting verbose flag is needed to avoid messy test progress output
681
- self ._config .option .verbose = 1
682
-
683
- with catching_logs (self .log_cli_handler , level = self .log_cli_level ):
684
- with catching_logs (self .log_file_handler , level = self .log_file_level ):
685
- yield # run all the tests
686
-
687
687
@pytest .hookimpl
688
688
def pytest_unconfigure (self ):
689
689
# Close the FileHandler explicitly.
0 commit comments