pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.31k stars 365 forks source link

Is it possible to only mock one command and run the rest with MockContext? #990

Open red8888 opened 3 months ago

red8888 commented 3 months ago

I have some integration tests where I do want to run some commands, but mock out the others.

Obviously I can just factor the code in a way that would let me monkey patch some functions but I'm curious if MockContext has supports this ootb.

For example, I can't do something like this can I? Or can I extend MockContext with this functionality somehow?

ctx = MockContext(
    run={
        "my cmd 1": Result(stdout="mock output"),
        "my cmd 3": Result(stdout="mock output"),
    },
    # Run the cmd for real in this block
    actually_run={
        "my cmd 2": Result(stdout="mock output"),
    }
)