question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocking a specific command only

See original GitHub issue

Apologies if I’m missing something obvious here but is there a way for me to only mock a specific command and for the client to use the real behaviour of the client of all the other commands? For a bit of context, I have a bunch of tests that run against dynamodb-local. I am trying to test a function that uses the batchWrite command but the function I’m testing makes other calls to dynamo before that. I would like to only mock the batchWrite function and allow the other commands to pass through to the local DB using the actual SDK. Is this possible?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
m-radzikowskicommented, Mar 14, 2022

You can access the underlying Sinon stub with:

mockClient.send

There is a stub.callThrough() method:

Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.

So you can try something like this:

mockClient.on(BatchWriteItemCommand).resolves({ ... }).
mockClient.send.callThrough();

No guarantee it will work, although please let me know if it does (or not).

1reaction
svozzacommented, Mar 14, 2022

That worked perfectly. Thanks for the prompt reply and moreover, thanks for the great library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocking a command and getting different results based on the ...
Mocking a command and getting different results based on the number of times the Mock is called · On the first call use...
Read more >
Is there an easier way to stub a specific command or script ...
I just found this bat-mock tool and it looks very promising for unit testing bash code. I wonder if there is any progress...
Read more >
Mock - Pester
This injects the mock into the specified module. If you do not specify a module name, the mock will be created in the...
Read more >
Enabling mocks from command-line (with py.test) - Medium
My goal was to be able to dynamically, via command-line parameters to py.test , switch certain mocks on and off, while using patch...
Read more >
unittest.mock — getting started — Python 3.11.1 documentation
Mocking Classes​​ A common use case is to mock out classes instantiated by your code under test. When you patch a class, then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found