Comment 3 for bug 2024601

Revision history for this message
Bryce Harrington (bryce) wrote :

The first testcase seems to fail only intermittently, I ran it 10 times to get a failure only once:

$ python3.11 -m pytest -v tests/test_browser.py::test_post
========================================== test session starts ===========================================
platform linux -- Python 3.11.4, pytest-7.2.1, pluggy-1.0.0+repack -- /usr/bin/python3.11
cachedir: .pytest_cache
rootdir: /tmp/autopkgtest
plugins: mock-3.8.2, requests-mock-1.9.3
collected 1 item

tests/test_browser.py::test_post FAILED [100%]

================================================ FAILURES ================================================
_______________________________________________ test_post ________________________________________________

httpbin = <utils.HttpbinRemote object at 0x7fb72b3e13d0>

    def test_post(httpbin):
        browser = mechanicalsoup.Browser()
        data = {'color': 'blue', 'colorblind': 'True'}
        resp = browser.post(httpbin + "/post", data)
> assert(resp.status_code == 200 and resp.json()['form'] == data)
E assert (504 == 200)
E + where 504 = <Response [504]>.status_code

tests/test_browser.py:149: AssertionError
======================================== short test summary info =========================================
FAILED tests/test_browser.py::test_post - assert (504 == 200)
=========================================== 1 failed in 10.27s ===========================================

The httpbin fixture is defined in tests/conftest.py as returning an HttpbinRemote() instance, which is defined in tests/utils.py as "http://httpbin.org". That website indeed seems to be online yet slow, and thus may account for why these tests are timing out. Indeed, utils.py includes a comment suggesting this is an intentional override:

class HttpbinRemote:
    """Drop-in replacement for pytest-httpbin's httpbin fixture
    that uses the remote httpbin server instead of a local one."""
    def __init__(self):
        self.url = "http://httpbin.org"

    def __add__(self, x):
        return self.url + x

If I install python3-pytest-httpbin and then comment out the httpbin fixture definition in conftest, then test_post seems to work better (it executes faster and no longer fails intermittently afaict), however the full testsuite still fails, presumably because the test cases still are not getting the data they're expecting.