pytest-xprocess icon indicating copy to clipboard operation
pytest-xprocess copied to clipboard

How to hide output while using the pattern option

Open patrick91 opened this issue 3 years ago • 1 comments

Is there a way to hide all the ouput while using the pattern option? I've tried this:

class Starter(ProcessStarter):
    env = {"PYTHONUNBUFFERED": "1", **os.environ}
    pattern = BOOT_MSG
    popen_kwargs = {
        "stdout": subprocess.DEVNULL,
        "stderr": subprocess.STDOUT,
    }

but it breaks the pattern check :)

patrick91 avatar Feb 23 '22 17:02 patrick91

Hey @patrick91. Yes, the code shown would naturally break pattern matching since you are effectively throwing away all process output so xprocess has nothing to match your pattern against. What output, specifically, would like to hide? Are you referring to pytest output? The output of the initialized process should be captured by pytest and should not show under normal circumstances (unless you disable all capture with -s flag). You can further customize pytest capturing with:

pytest -s                  # disable all capturing
pytest --capture=sys       # replace sys.stdout/stderr with in-mem files
pytest --capture=fd        # also point filedescriptors 1 and 2 to temp file
pytest --capture=tee-sys   # combines 'sys' and '-s', capturing sys.stdout/stderr
                           # and passing it along to the actual sys.stdout/stderr

northernSage avatar Mar 13 '22 01:03 northernSage