Example #1
0
def test_send_control_c():
    """Test send control c to process."""
    # Can't test process group id kill directly,
    # because o/w pytest would be stopped.
    process = Popen(  # nosec
        ["timeout" if platform.system() == "Windows" else "sleep", "5"],
        **win_popen_kwargs())
    time.sleep(0.001)
    send_control_c(process)
    process.communicate(timeout=3)
    assert process.returncode != 0
Example #2
0
    def _run_python_subprocess(cls, *args: str, cwd: str = ".") -> subprocess.Popen:
        """
        Run python with args as subprocess.

        :param args: CLI args

        :return: subprocess object.
        """
        kwargs = dict(
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            env=os.environ.copy(),
            cwd=cwd,
        )
        kwargs.update(win_popen_kwargs())

        process = subprocess.Popen(  # type: ignore # nosec # mypy fails on **kwargs
            [sys.executable, *args], **kwargs,
        )
        cls.subprocesses.append(process)
        return process