File tree Expand file tree Collapse file tree 3 files changed +48
-10
lines changed Expand file tree Collapse file tree 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 @@ -424,10 +424,6 @@ def __init__(self, config):
424424 """
425425 self ._config = config
426426
427- # enable verbose output automatically if live logging is enabled
428- if self ._log_cli_enabled () and config .getoption ("verbose" ) < 1 :
429- config .option .verbose = 1
430-
431427 self .print_logs = get_option_ini (config , "log_print" )
432428 self .formatter = self ._create_formatter (
433429 get_option_ini (config , "log_format" ),
@@ -644,6 +640,15 @@ def pytest_sessionstart(self):
644640 @pytest .hookimpl (hookwrapper = True )
645641 def pytest_runtestloop (self , session ):
646642 """Runs all collected test items."""
643+
644+ if session .config .option .collectonly :
645+ yield
646+ return
647+
648+ if self ._log_cli_enabled () and self ._config .getoption ("verbose" ) < 1 :
649+ # setting verbose flag is needed to avoid messy test progress output
650+ self ._config .option .verbose = 1
651+
647652 with self .live_logs_context ():
648653 if self .log_file_handler is not None :
649654 with catching_logs (self .log_file_handler , level = self .log_file_level ):
Original file line number Diff line number Diff line change @@ -921,14 +921,45 @@ def test_collection_live_logging(testdir):
921921
922922 result = testdir .runpytest ("--log-cli-level=INFO" )
923923 result .stdout .fnmatch_lines (
924- [
925- "collecting*" ,
926- "*--- live log collection ---*" ,
927- "*Normal message*" ,
928- "collected 0 items" ,
929- ]
924+ ["*--- live log collection ---*" , "*Normal message*" , "collected 0 items" ]
925+ )
926+
927+
928+ @pytest .mark .parametrize ("verbose" , ["" , "-q" , "-qq" ])
929+ def test_collection_collect_only_live_logging (testdir , verbose ):
930+ testdir .makepyfile (
931+ """
932+ def test_simple():
933+ pass
934+ """
930935 )
931936
937+ result = testdir .runpytest ("--collect-only" , "--log-cli-level=INFO" , verbose )
938+
939+ expected_lines = []
940+
941+ if not verbose :
942+ expected_lines .extend (
943+ [
944+ "*collected 1 item*" ,
945+ "*<Module test_collection_collect_only_live_logging.py>*" ,
946+ "*no tests ran*" ,
947+ ]
948+ )
949+ elif verbose == "-q" :
950+ assert "collected 1 item*" not in result .stdout .str ()
951+ expected_lines .extend (
952+ [
953+ "*test_collection_collect_only_live_logging.py::test_simple*" ,
954+ "no tests ran in * seconds" ,
955+ ]
956+ )
957+ elif verbose == "-qq" :
958+ assert "collected 1 item*" not in result .stdout .str ()
959+ expected_lines .extend (["*test_collection_collect_only_live_logging.py: 1*" ])
960+
961+ result .stdout .fnmatch_lines (expected_lines )
962+
932963
933964def test_collection_logging_to_file (testdir ):
934965 log_file = testdir .tmpdir .join ("pytest.log" ).strpath
You can’t perform that action at this time.
0 commit comments