getting the valid input in mock
See original GitHub issueHi,
I tried to mock the input type of a function create_service
in services.py
.
from mockito import verify, when, ANY, not_
from .api import services
from .models import Token
class TestCreateServicePrincipal(TestCase):
def test_input_name_service_principal(self):
when(services).create_service(ANY(Token), ANY(str), None, None, "p",False).thenReturn(1)
when(services).create_service(not_(ANY(Token)), ANY(str), None, None, "p",False).thenRaise(TypeError)
when(services).create_service(ANY(Token), not_( ANY(str)), None, None, "p",False).thenRaise(TypeError)
when(services).create_service(not_(ANY(Token)), not_( ANY(str)), None, None, "p",False).thenRaise(TypeError)
verify(services).create_service(ANY(Token), ANY(str), None, None, "p",False)
#verify(services).create_service(not_(ANY(Token)), ANY(str), None, None, "p",False)
#verify(services).create_service(ANY(Token), not_( ANY(str)), None, None, "p",False).thenRaise(TypeError)
#verify(services).create_service(not_(ANY(Token)), not_( ANY(str)), None, None, "p",False).thenRaise(TypeError)
I am setting up a mock with when
and then using verify
to evaluate the valid or invalid inputs but I got the following error. Is there any way I can fix the error?
mockito.verification.VerificationError: Wanted but not invoked: create_service(<Any: <class 'Token'>>, <Any: <class 'str'>>, None, None, 'p', False) Instead got: Nothing
Issue Analytics
- State:
- Created a year ago
- Comments:58 (27 by maintainers)
Top Results From Across the Web
Verifying a specific parameter with Moq - Stack Overflow
Partial answer: I've found a way to test that the xml sent to the proxy is correct, but I still don't think it's...
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Obtaining Mockito. Getting Mockito is easy these days. ... Mockito ensures that the exception being thrown is valid for that specific stubbed method...
Read more >unittest.mock — mock object library — Python 3.11.1 ...
This allows mocks to pass isinstance() tests. spec_set: A stricter variant of spec. If used, attempting to set or get an attribute on...
Read more >Change a Function's Output Based on Input Parameter Value ...
Here's an example on how we could mock the network_operation function so it ... run an HTTP request and it always returns the...
Read more >Stubbing and Mocking in Java with the Spock Testing ...
Learn how to create true Java unit tests by mocking all external dependencies in your unit tests with the Spock testing framework.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah sure, part of what Typer seems to do is that it injects a context object here. You need to find out where this ctx comes from. Why is there an
obj
on it. Where does thedebug
(ctx.obj.debug
) come from. And how can you modify and control the typer.Context in your tests.is there any way I can get the json output when I do not patch
output_json
?