Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#990 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
testing

Research direction

Start with the MockContext entry point and inspect the surrounding test coverage. Determine whether a context can selectively mock commands while allowing others to execute, then define the behavior and tests needed for a supported solution.

Written by the indexing model from the issue text.

Description

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"),
    }
)
Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.