pallets / werkzeug

The comprehensive WSGI web application library.
https://werkzeug.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
6.66k stars 1.73k forks source link

test_serving.py hangs #3002

Closed 0-wiz-0 closed 2 weeks ago

0-wiz-0 commented 2 weeks ago

I've been updating the werkzeug package for pkgsrc. Starting with 3.1.0 (still there in 3.1.3) I see a test hang in test_serving.py. If I remove the file, most other tests pass except for

___________________________________________________________________________________________________ test_get_machine_id ____________________________________________________________________________________________________

    def test_get_machine_id():
        rv = get_machine_id()
>       assert isinstance(rv, bytes)
E       assert False
E        +  where False = isinstance(None, bytes)

tests/test_debug.py:245: AssertionError
================================================================================================= short test summary info ==================================================================================================
FAILED tests/test_debug.py::test_get_machine_id - assert False

I'm using the pypi source distfile, and run the tests after building and installing werkzeug by running pytest in the build directory. The output looks like this:

tests/middleware/test_dispatcher.py .                                                                                                                                                                                [  0%]
tests/middleware/test_http_proxy.py .                                                                                                                                                                                [  0%]
tests/middleware/test_lint.py .........                                                                                                                                                                              [  1%]
tests/middleware/test_profiler.py .                                                                                                                                                                                  [  1%]
tests/middleware/test_proxy_fix.py .................                                                                                                                                                                 [  3%]
tests/middleware/test_shared_data.py ..                                                                                                                                                                              [  3%]
tests/sansio/test_multipart.py .....................                                                                                                                                                                 [  5%]
tests/sansio/test_request.py .........                                                                                                                                                                               [  6%]
tests/sansio/test_utils.py ........................                                                                                                                                                                  [  8%]
tests/test_datastructures.py ...........................................................................................................................                                                             [ 21%]
tests/test_debug.py ...............F.....                                                                                                                                                                            [ 24%]
tests/test_exceptions.py ............................................................................................                                                                                                [ 33%]
tests/test_formparser.py ...........................                                                                                                                                                                 [ 36%]
tests/test_http.py ........................................................................................................................                                                                          [ 49%]
tests/test_internal.py .                                                                                                                                                                                             [ 49%]
tests/test_local.py ...............................................................                                                                                                                                  [ 56%]
tests/test_routing.py .....................................................................................................................                                                                          [ 68%]
tests/test_security.py ............                                                                                                                                                                                  [ 69%]
tests/test_send_file.py ................................                                                                                                                                                             [ 73%]
tests/test_serving.py .

and then nothing happens.

Can you please advise how to debug/fix this? Thanks.

Environment:

davidism commented 2 weeks ago

It sounds like you're running the tests in a custom way. The server tests are likely sensitive to the current directory and sys.path, so if things are out of place they may not start correctly. Note that they also start servers listening on random high ports bound to the local interface, so that needs to be available in your environment. I ran the build and tests from sdist for version 3.1.3 in the following way:

# get the 3.1.3 sdist from pypi
$ curl -O https://files.pythonhosted.org/packages/9f/69/83029f1f6300c5fb2471d621ab06f6ec6b3324685a2ce0f9777fd4a8b71e/werkzeug-3.1.3.tar.gz
$ tar xf werkzeug-3.1.3.tar.gz
$ cd werkzeug-3.1.3

# create a virtualenv
$ python3.13 -m venv .venv
$ . .venv/bin/activate

# install the build and test requirements
$ pip install -r requirements/build.txt -r requirements/tests.txt

# build and install the wheel
$ python -m build
$ pip install dist/werkzeug-3.1.3-py3-none-any.whl

# run pytest
$ pytest

All tests pass successfully.