File tree Expand file tree Collapse file tree 3 files changed +41
-10
lines changed Expand file tree Collapse file tree 3 files changed +41
-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):
409409 """
410410 self ._config = config
411411
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-
416412 self .print_logs = get_option_ini (config , "log_print" )
417413 self .formatter = self ._create_formatter (
418414 get_option_ini (config , "log_format" ),
@@ -628,6 +624,10 @@ def pytest_sessionstart(self):
628624 @pytest .hookimpl (hookwrapper = True )
629625 def pytest_runtestloop (self , session ):
630626 """Runs all collected test items."""
627+ if self ._log_cli_enabled () and self ._config .getoption ("verbose" ) < 1 :
628+ # setting verbose flag is needed to avoid messy test progress output
629+ self ._config .option .verbose = 1
630+
631631 with self .live_logs_context ():
632632 if self .log_file_handler is not None :
633633 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,43 @@ def test_collection_live_logging(testdir):
916916
917917 result = testdir .runpytest ("--log-cli-level=INFO" )
918918 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+ """
925930 )
926931
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+ ]
942+ )
943+ elif verbose == "-q" :
944+ assert "collected 1 item*" not in result .stdout .str ()
945+ expected_lines .extend (
946+ ["*test_collection_collect_only_live_logging.py::test_simple*" ]
947+ )
948+ elif verbose == "-qq" :
949+ assert "collected 1 item*" not in result .stdout .str ()
950+ expected_lines .extend (["*test_collection_collect_only_live_logging.py: 1*" ])
951+
952+ expected_lines .append ("*no tests ran*" )
953+
954+ result .stdout .fnmatch_lines (expected_lines )
955+
927956
928957def test_collection_logging_to_file (testdir ):
929958 log_file = testdir .tmpdir .join ("pytest.log" ).strpath
You can’t perform that action at this time.
0 commit comments