@@ -90,6 +90,21 @@ def control_port():
90
90
91
91
# ---------------------- Module initialization ---------------------------
92
92
93
+ def avoid_duplicated_logs ():
94
+ """
95
+ Remove direct root logger output to file descriptors.
96
+ This default is causing duplicates because all our messages go through
97
+ regular logging as well and are thus displayed twice.
98
+ """
99
+ todel = []
100
+ for handler in logging .root .handlers :
101
+ if handler .__class__ == logging .StreamHandler :
102
+ # Beware: As for pytest 7.2.2, LiveLogging and LogCapture
103
+ # handlers inherit from logging.StreamHandler
104
+ todel .append (handler )
105
+ for handler in todel :
106
+ logging .root .handlers .remove (handler )
107
+
93
108
def parse_env (env_text ):
94
109
"""Parse the POSIX env format into Python dictionary."""
95
110
out = {}
@@ -282,6 +297,7 @@ def system_test_name(request):
282
297
@pytest .fixture (scope = "module" )
283
298
def logger (system_test_name ):
284
299
"""Logging facility specific to this test."""
300
+ avoid_duplicated_logs ()
285
301
return logging .getLogger (system_test_name )
286
302
287
303
@pytest .fixture (scope = "module" )
@@ -377,29 +393,26 @@ def _run_script( # pylint: disable=too-many-arguments
377
393
raise FileNotFoundError (f"script { script } not found in { cwd } " )
378
394
logger .debug ("running script: %s %s %s" , interpreter , script , " " .join (args ))
379
395
logger .debug (" workdir: %s" , cwd )
380
- stdout = b""
381
396
returncode = 1
382
- try :
383
- proc = subprocess .run (
384
- [interpreter , script ] + args ,
385
- env = env ,
386
- check = True ,
387
- stdout = subprocess .PIPE ,
388
- stderr = subprocess .STDOUT ,
389
- )
390
- except subprocess .CalledProcessError as exc :
391
- stdout = exc .stdout
392
- returncode = exc .returncode
393
- raise exc
394
- else :
395
- stdout = proc .stdout
397
+
398
+ cmd = [interpreter , script ] + args
399
+ with subprocess .Popen (
400
+ cmd ,
401
+ env = env ,
402
+ stdout = subprocess .PIPE ,
403
+ stderr = subprocess .STDOUT ,
404
+ bufsize = 1 ,
405
+ universal_newlines = True ,
406
+ errors = 'backslashreplace'
407
+ ) as proc :
408
+ if proc .stdout :
409
+ for line in proc .stdout :
410
+ logger .info (" %s" , line .rstrip ('\n ' ))
411
+ proc .communicate ()
396
412
returncode = proc .returncode
397
- finally :
398
- if stdout :
399
- for line in stdout .decode ().splitlines ():
400
- logger .debug (" %s" , line )
413
+ if returncode :
414
+ raise subprocess .CalledProcessError (returncode , cmd )
401
415
logger .debug (" exited with %d" , returncode )
402
- return proc
403
416
404
417
@pytest .fixture (scope = "module" )
405
418
def shell (env , system_test_dir , logger ):
0 commit comments