-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reusing settings from a MockRouter instance on MockRouter.__call__ #181
Comments
This is a great suggestion and enhancement of the router settings. I think this could be solved by adding a Something like this: my_mock_api = respx.mock(assert_all_called=False)
...
@my_mock_api
def test_somthing_else():
...
# won't assert that all routes have been called when exiting this test case
@my_mock_api
def test_something():
my_mock_api.configure(assert_all_called=True)
...
# will assert that all routes have been called when exiting this test case
|
I gave this a try a few days ago @flaeppe, and got stuck on a "problem" with the How it works is that the base URL is turned into a bases pattern by the router, and in turn merged to each added route. We need a way to alter/clone any existing routes' patterns if they have previous bases. This is also mentioned in #186. About the |
Cool, yeah. Some additional
One initial idea could be to "postpone" merging until matching/comparison happens, though that will come with a performance hit, not sure how severe that would be though. Or if it could be mitigated with some But if I'm interpreting you right here, the problematic part is that bases are merged with each route and we have no way of "rewinding" that merge? So that we can only edit the bases patterns. |
Correct @flaeppe. At the moment, I'm trying to actually implement a rewind feature, or more correctly adjust the Also to get that working, I had to implement |
Side note...this would be of interest even for #190 in the case a route is added to the default global |
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 aMockRouter
with defaults, and for specific test cases flip theassert_all_called
-flag.Consider the code below. I want
base_url
andassert_all_called
to have its default, unless they're overriden by a new__call__
invocationCurrently, this gives me an error whenever I pass in new kwargs to
default
(test_1
andwith default
). As__call__
is just creating a newMockRouter
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__
.The text was updated successfully, but these errors were encountered: