Inject command into Results returned by a MockContext #700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A small pull request to make MockContext's
.run()and.sudo()returnResultswith thecommandattribute set.From my own use cases, the
commandattribute is the only one I ever seem to need. I frequently create a layer of simple tasks, upon which I create more complex tasks that will call the others. Proper unit testing requires me to check that all parameters are properly passed to the lower tasks, ie. that they contruct the right command for thectx.run().Therefore, in this use case, I cannot provide
commandto theResult()constructor and I need some way to get at the actual command so I can test it.So I wrote these small modifications to the
MockContext.run()andMockContext.sudo()methods. If acommandis given to theResult()constructor, it is of course retained, otherwise the actual command is injected.While I believe that this is the most likely use case for such an injection, I would keep the TODO remarks about maybe one day injecting other args/kwargs as well, as I don't believe we can be 100% certain those will never be useful...