File tree 3 files changed +48
-10
lines changed 3 files changed +48
-10
lines changed Original file line number Diff line number Diff line change
1
+ ``-q `` has again an impact on the style of the collected items
2
+ (``--collect-only ``) when ``--log-cli-level `` is used.
Original file line number Diff line number Diff line change @@ -409,10 +409,6 @@ def __init__(self, config):
409
409
"""
410
410
self ._config = config
411
411
412
- # enable verbose output automatically if live logging is enabled
413
- if self ._log_cli_enabled () and config .getoption ("verbose" ) < 1 :
414
- config .option .verbose = 1
415
-
416
412
self .print_logs = get_option_ini (config , "log_print" )
417
413
self .formatter = self ._create_formatter (
418
414
get_option_ini (config , "log_format" ),
@@ -628,6 +624,15 @@ def pytest_sessionstart(self):
628
624
@pytest .hookimpl (hookwrapper = True )
629
625
def pytest_runtestloop (self , session ):
630
626
"""Runs all collected test items."""
627
+
628
+ if session .config .option .collectonly :
629
+ yield
630
+ return
631
+
632
+ if self ._log_cli_enabled () and self ._config .getoption ("verbose" ) < 1 :
633
+ # setting verbose flag is needed to avoid messy test progress output
634
+ self ._config .option .verbose = 1
635
+
631
636
with self .live_logs_context ():
632
637
if self .log_file_handler is not None :
633
638
with catching_logs (self .log_file_handler , level = self .log_file_level ):
Original file line number Diff line number Diff line change @@ -916,14 +916,45 @@ def test_collection_live_logging(testdir):
916
916
917
917
result = testdir .runpytest ("--log-cli-level=INFO" )
918
918
result .stdout .fnmatch_lines (
919
- [
920
- "collecting*" ,
921
- "*--- live log collection ---*" ,
922
- "*Normal message*" ,
923
- "collected 0 items" ,
924
- ]
919
+ ["*--- live log collection ---*" , "*Normal message*" , "collected 0 items" ]
920
+ )
921
+
922
+
923
+ @pytest .mark .parametrize ("verbose" , ["" , "-q" , "-qq" ])
924
+ def test_collection_collect_only_live_logging (testdir , verbose ):
925
+ testdir .makepyfile (
926
+ """
927
+ def test_simple():
928
+ pass
929
+ """
925
930
)
926
931
932
+ result = testdir .runpytest ("--collect-only" , "--log-cli-level=INFO" , verbose )
933
+
934
+ expected_lines = []
935
+
936
+ if not verbose :
937
+ expected_lines .extend (
938
+ [
939
+ "*collected 1 item*" ,
940
+ "*<Module test_collection_collect_only_live_logging.py>*" ,
941
+ "*no tests ran*" ,
942
+ ]
943
+ )
944
+ elif verbose == "-q" :
945
+ assert "collected 1 item*" not in result .stdout .str ()
946
+ expected_lines .extend (
947
+ [
948
+ "*test_collection_collect_only_live_logging.py::test_simple*" ,
949
+ "no tests ran in * seconds" ,
950
+ ]
951
+ )
952
+ elif verbose == "-qq" :
953
+ assert "collected 1 item*" not in result .stdout .str ()
954
+ expected_lines .extend (["*test_collection_collect_only_live_logging.py: 1*" ])
955
+
956
+ result .stdout .fnmatch_lines (expected_lines )
957
+
927
958
928
959
def test_collection_logging_to_file (testdir ):
929
960
log_file = testdir .tmpdir .join ("pytest.log" ).strpath
You can’t perform that action at this time.
0 commit comments