Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex matching commands #154

Open
LecrisUT opened this issue May 10, 2024 · 3 comments
Open

Regex matching commands #154

LecrisUT opened this issue May 10, 2024 · 3 comments

Comments

@LecrisUT
Copy link

I want to mock specific calls to subprocess but the command inputs are varying, e.g. cmake -S/path/to/generated_data -B/random/build_path. I would thus like to use regex match these arguments and make sure other commands like cmake --build are not called.

@aklajnert
Copy link
Owner

There is no regex support at the moment, but perhaps you can make use of the non-exact command matching feature: https://pytest-subprocess.readthedocs.io/en/latest/usage.html#non-exact-command-matching

@LecrisUT
Copy link
Author

I can partially use it, but I want to selectively mock these, i.e. ["cmake", "--build", fp.any(min=1)] (succeed), ["cmake", re.compile(r"-S\S*"), re.comiple(r"-B\S*"), fp.any()] (succeed), ["cmake", fp.any()] (everything else must fail)

My suggestion here is to allow to pass it re.compile if we want to check regex. It would be nice to pass it only r-string, but I don't think that would tell us if it's regex or not.

@aklajnert
Copy link
Owner

I agree that regex may be helpful here. I'll try to add support for it soon, but I can't promise anything. Feel free to submit a PR with your proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants