pytest-httpserver: 1.0.11: `test_verify_assert_msg` and `test_verify_assert_msg_no_similar_requests` fails

I ran tests for 1.0.11 sdist using pytest and both test_verify_assert_msg and test_verify_assert_msg_no_similar_requests tests fails:

=================================== FAILURES ===================================
____________________________ test_verify_assert_msg ____________________________

httpserver = <HTTPServer host=localhost port=44239>

    def test_verify_assert_msg(httpserver: HTTPServer):
        httpserver.no_handler_status_code = 404
        httpserver.expect_request("/foo", json={"foo": "bar"}, method="POST").respond_with_data("OK")
        assert requests.get(httpserver.url_for("/foo"), headers={"User-Agent": "requests"}).status_code == 404
    
        with pytest.raises(AssertionError) as err:
            httpserver.assert_request_made(RequestMatcher("/foo", json={"foo": "bar"}, method="POST"))
    
        expected_message = f"""Matching request found 0 times but expected 1 times.
    Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={{}} data=None json={{'foo': 'bar'}}>
    Found 1 similar request(s):
    --- Similar Request Start
    Path: /foo
    Method: GET
    Body: b''
    Headers: Host: localhost:{httpserver.port}\r
    User-Agent: requests\r
    Accept-Encoding: gzip, deflate\r
    Accept: */*\r
    Connection: keep-alive\r
    \r
    
    Query String: ''
    --- Similar Request End
    """  # noqa: E501
>       assert str(err.value) == expected_message
E       assert "Matching request found 0 times but expected 1 times.\n  Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\n  Found 1 similar request(s):\n  --- Similar Request Start\n  Path: /foo\n  Method: GET\n  Body: b''\n  Headers: Host: localhost:44239\r\n  User-Agent: requests\r\n  Accept-Encoding: gzip, deflate, br, zstd\r\n  Accept: */*\r\n  Connection: keep-alive\r\n  \r\n  \n  Query String: ''\n  --- Similar Request End\n  \nassert 0 == 1" == "Matching request found 0 times but expected 1 times.\nExpected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\nFound 1 similar request(s):\n--- Similar Request Start\nPath: /foo\nMethod: GET\nBody: b''\nHeaders: Host: localhost:44239\r\nUser-Agent: requests\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n\nQuery String: ''\n--- Similar Request End\n"
E         
E           Matching request found 0 times but expected 1 times.
E         - Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
E         +   Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
E         ? ++
E         - Found 1 similar request(s):
E         +   Found 1 similar request(s):
E         ? ++
E         - --- Similar Request Start
E         +   --- Similar Request Start
E         ? ++
E         - Path: /foo
E         +   Path: /foo
E         ? ++
E         - Method: GET
E         +   Method: GET
E         ? ++
E         - Body: b''
E         +   Body: b''
E         ? ++
E         - Headers: Host: localhost:44239
E         +   Headers: Host: localhost:44239
E         ? ++
E         - User-Agent: requests
E         +   User-Agent: requests
E         ? ++
E         - Accept-Encoding: gzip, deflate
E         +   Accept-Encoding: gzip, deflate, br, zstd
E         ? ++                              ++++++++++
E         - Accept: */*
E         +   Accept: */*
E         ? ++
E         - Connection: keep-alive
E         +   Connection: keep-alive
E         ? ++
E         - 
E         - 
E         +   
E         +   
E         - Query String: ''
E         +   Query String: ''
E         ? ++
E         - --- Similar Request End
E         +   --- Similar Request End
E         ? ++
E         +   
E         + assert 0 == 1

tests/test_log_querying.py:60: AssertionError
------------------------------ Captured log call -------------------------------
INFO     werkzeug:_internal.py:97 127.0.0.1 - - [20/Jul/2024 15:55:06] "GET /foo HTTP/1.1" 404 -
__________________ test_verify_assert_msg_no_similar_requests __________________

httpserver = <HTTPServer host=localhost port=44239>

    def test_verify_assert_msg_no_similar_requests(httpserver: HTTPServer):
        httpserver.expect_request("/foo", json={"foo": "bar"}, method="POST").respond_with_data("OK")
    
        with pytest.raises(AssertionError) as err:
            httpserver.assert_request_made(RequestMatcher("/foo", json={"foo": "bar"}, method="POST"))
    
        expected_message = """Matching request found 0 times but expected 1 times.
    Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
    No similar requests found.
    """
>       assert str(err.value) == expected_message
E       assert "Matching request found 0 times but expected 1 times.\n  Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\n  No similar requests found.\n  \nassert 0 == 1" == "Matching request found 0 times but expected 1 times.\nExpected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\nNo similar requests found.\n"
E         
E           Matching request found 0 times but expected 1 times.
E         - Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
E         +   Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
E         ? ++
E         - No similar requests found.
E         +   No similar requests found.
E         ? ++
E         +   
E         + assert 0 == 1

tests/test_log_querying.py:73: AssertionError
=========================== short test summary info ============================
FAILED tests/test_log_querying.py::test_verify_assert_msg - assert "Matching request found 0 times but expected 1 times.\n  Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\n  Found 1 similar request(s):\n  --- Similar Request Start\n  Path: /foo\n  Method: GET\n  Body: b''\n  Headers: Host: localhost:44239\r\n  User-Agent: requests\r\n  Accept-Encoding: gzip, deflate, br, zstd\r\n  Accept: */*\r\n  Connection: keep-alive\r\n  \r\n  \n  Query String: ''\n  --- Similar Request End\n  \nassert 0 == 1" == "Matching request found 0 times but expected 1 times.\nExpected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\nFound 1 similar request(s):\n--- Similar Request Start\nPath: /foo\nMethod: GET\nBody: b''\nHeaders: Host: localhost:44239\r\nUser-Agent: requests\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n\nQuery String: ''\n--- Similar Request End\n"
  
    Matching request found 0 times but expected 1 times.
  - Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
  +   Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
  ? ++
  - Found 1 similar request(s):
  +   Found 1 similar request(s):
  ? ++
  - --- Similar Request Start
  +   --- Similar Request Start
  ? ++
  - Path: /foo
  +   Path: /foo
  ? ++
  - Method: GET
  +   Method: GET
  ? ++
  - Body: b''
  +   Body: b''
  ? ++
  - Headers: Host: localhost:44239
  +   Headers: Host: localhost:44239
  ? ++
  - User-Agent: requests
  +   User-Agent: requests
  ? ++
  - Accept-Encoding: gzip, deflate
  +   Accept-Encoding: gzip, deflate, br, zstd
  ? ++                              ++++++++++
  - Accept: */*
  +   Accept: */*
  ? ++
  - Connection: keep-alive
  +   Connection: keep-alive
  ? ++
  - 
  - 
  +   
  +   
  - Query String: ''
  +   Query String: ''
  ? ++
  - --- Similar Request End
  +   --- Similar Request End
  ? ++
  +   
  + assert 0 == 1
FAILED tests/test_log_querying.py::test_verify_assert_msg_no_similar_requests - assert "Matching request found 0 times but expected 1 times.\n  Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\n  No similar requests found.\n  \nassert 0 == 1" == "Matching request found 0 times but expected 1 times.\nExpected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>\nNo similar requests found.\n"
  
    Matching request found 0 times but expected 1 times.
  - Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
  +   Expected request: <RequestMatcher uri='/foo' method='POST' query_string=None headers={} data=None json={'foo': 'bar'}>
  ? ++
  - No similar requests found.
  +   No similar requests found.
  ? ++
  +   
  + assert 0 == 1
============= 2 failed, 99 passed, 8 skipped, 1 xfailed in 12.59s ==============

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I also can confirm that tests are passing fine in version 1.0.12 in Arch Linux.

Thank for the assistance and for fixing this!

All tests pass for me with version 1.0.12 sdist. Thank you!

@mtelka @dbermond

Version 1.0.12 just has been released with the fix to pypi. I checked it on my host and I could ran the sdist tests with the pytest-httpserver installed from wheel to the venv. So I hope it will be fixed for you as well. If not, feel free to re-open this issue.

I’ll also to a RCA later on as this was totally unexpected.

Thanks for the report! Zsolt

I pushed a fix to the fix-345 branch, could you please re-run the test on it?

This should fix both errors you reported.

@csernazs Using branch fix-345 with the new commits added today fixes both issues for me.

Thank you for fixing this.

Do you intend to release a new version with the fixes or will it stay only in git master for the time being?

Thanks!

Yes, I want to release a view version with the fix as it is included in sdist, and the tests don’t work with the released wheel.

I’ll update the ticket when it is ready.

Zsolt