-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I'm wondering if it could be possible to support reusing some settings of a MockRouter instance, when invoking __call__. Basically that'll allow me to specify a MockRouter with defaults, and for specific test cases flip the assert_all_called-flag.
Consider the code below. I want base_url and assert_all_called to have its default, unless they're overriden by a new __call__ invocation
import httpx
import respx
default = respx.mock(base_url="http://some.where/", assert_all_called=False)
default.get(path="/here/")
with default(assert_all_called=True):
httpx.get("http://some.where/here/") # Raises: RESPX: <Request('GET', 'http://some.where/here/')> not mocked!
@default(assert_all_called=True)
def test_1():
httpx.get("http://some.where/here/") # Raises: RESPX: <Request('GET', 'http://some.where/here/')> not mocked!
test_1()
# This should still have the default `assert_all_called=False`
@default
def test_2():
httpx.get("http://some.where/here/") # This works
test_2()Currently, this gives me an error whenever I pass in new kwargs to default(test_1 and with default). As __call__ is just creating a new MockRouter instance from scratch.
I'm realising as I write this that support for this might appear better through some additional MockRouter method (e.g. MockRouter.replace()) instead of changing __call__.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request