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.

getting the valid input in mock

See original GitHub issue

Hi,

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:closed
  • Created a year ago
  • Comments:58 (27 by maintainers)

github_iconTop GitHub Comments

1reaction
kastecommented, Jul 19, 2022

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 the debug (ctx.obj.debug) come from. And how can you modify and control the typer.Context in your tests.

0reactions
dvu4commented, Jul 21, 2022

is there any way I can get the json output when I do not patch output_json ?

Read more comments on GitHub >

github_iconTop 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 >

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