Skip to content

The Popen patching is a little fragile #116

@gipi

Description

@gipi

If you use from multiprocess import Popen the library is not able to swap the implementation, I don't know if it's an intended behavior, maybe should be explicitly indicated in the documentation.

Minimal reproducible example: imagine you have the module benchmarking.py with the following function:

from subprocess import Popen as imported_Popen

def meow(cmdline):
    return imported_Popen(cmdline, stdout=subprocess.PIPE)

and then you have a separate file with your test

from benchmarking import meow

def test_echo_null_byte(fp):
    fp.register(["echo", "-ne", "\x00"], stdout=bytes.fromhex("00"))

    process = meow(["echo", "-ne", "\x00"])
    out, _ = process.communicate()

    assert process.returncode == 0
    assert out == b"\x00"

then the test it's gonna fail because (probably) at the moment the test is run it's too late to swap the implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions