1

我需要根据通过HTTPretty的 GET 参数返回不同的响应:

@httpretty.activate
def test_multiple_requests():
    httpretty.register_uri(httpretty.GET, 'https://example.com/data.xml?n=0',
                           body='0')

    httpretty.register_uri(httpretty.GET, 'https://example.com/data.xml?n=1',
                           body='1')

    r = requests.get('https://example.com/data.xml?n=0')
    print(r.text)

    r = requests.get('https://example.com/data.xml?n=1')
    print(r.text)

此代码打印以下内容:

1
0

为什么?我认为它应该是

0
1

反而。

4

0 回答 0