Skip to content

responses.add_callback triggers DeprecationWarning beyond user's control #464

@mblayman

Description

@mblayman

Steps to Reproduce

My company uses responses in combination with pytest with deprecation warnings treated as failures. The dependabot upgrade from 0.16.0 to 0.17.0 failed.

This test (which I've scrubbed to avoid sharing irrelevant and company sensitive details) triggers a DeprecationWarning upon execution.

    @responses.activate
    def test_something(self, caplog):
        # setup elided
    
        def request_callback(request):
            """Used to validate that the request correctly sets the status to deleted"""
            payload = json.loads(request.body)
            assert payload['StatusType'] == SOME_CONSTANT_TO_CHECK
            return 200, {}, json.dumps(SOME_RESPONSE_DATA)
    
       responses.add_callback(
            responses.POST, '/a/url/path', callback=request_callback
       )

Here is the warning:

E           DeprecationWarning: Argument 'match_querystring' is deprecated.
Use 'responses.matchers.query_param_matcher' or 'responses.matchers.query_string_matcher'

Expected Result

This test makes no use of match_querystring. I would not expect to see a deprecation warning.

Actual Result

A deprecation warning triggered.

I believe the reason is because add_callback sets match_querystring to False by default (see https://github.com/getsentry/responses/blob/0.17.0/responses/__init__.py#L719).

_should_match_querystring, the method where the deprecation warning is triggered, expects the more exact check of if match_querystring_argument is not None: (see https://github.com/getsentry/responses/blob/0.17.0/responses/__init__.py#L333)

My guess is that _should_match_querystring should be able to check the False value too to prevent disruption to the add_callback API.

Thanks for the help. Please let me know if I can do more to help or if more information is needed.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions