Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter readBody deprecation notice in tests #947

Merged
merged 4 commits into from Sep 18, 2023
Merged

Filter readBody deprecation notice in tests #947

merged 4 commits into from Sep 18, 2023

Conversation

karezachen
Copy link
Contributor

@karezachen karezachen commented Jul 30, 2023

#670

Using readBody with a transport that does not haven an abortConnection method will trigger the deprecation warning.

Can refer to #twisted-issue-7762.

So I use _read_response_body method instead of readBody method and now everything works fine with the use case.

Before

cmd

python3.9 -m pytest tests/test_twisted.py

result

==================================================================== test session starts =====================================================================
platform darwin -- Python 3.9.17, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 1 item

tests/test_twisted.py .                                                                                                                                [100%]

====================================================================== warnings summary ======================================================================
tests/test_twisted.py::MetricsResourceTest::test_reports_metrics
  /Users/chenyiqiang/.pyenv/versions/3.9.17/lib/python3.9/site-packages/twisted/internet/defer.py:892: DeprecationWarning: Using readBody with a transport that does not have an abortConnection method
    current.result = callback(  # type: ignore[misc]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================ 1 passed, 1 warning in 0.80s ================================================================

After

cmd

python3.9 -m pytest tests/test_twisted.py

result

==================================================================== test session starts =====================================================================
platform darwin -- Python 3.9.17, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 1 item

tests/test_twisted.py .                                                                                                                                [100%]

===================================================================== 1 passed in 0.48s ======================================================================

@karezachen
Copy link
Contributor Author

tox result

coverage-clean: commands[0]> coverage erase
coverage-clean: OK ✔ in 0.4 seconds
.pkg: _optional_hooks> python /usr/local/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /usr/local/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python /usr/local/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: prepare_metadata_for_build_wheel> python /usr/local/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /usr/local/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py3.8: install_package> python -I -m pip install --force-reinstall --no-deps /Users/chenyiqiang/WorkSpace/prometheus/client_python/.tox/.tmp/package/5/prometheus_client-0.17.1.tar.gz
py3.8: commands[0]> coverage run --parallel -m pytest
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.8.17, pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/py3.8/.pytest_cache
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 303 items

tests/test_asgi.py ........                                                                                                                            [  2%]
tests/test_core.py ...................................................................................................                                 [ 35%]
tests/test_exposition.py ..........................................................                                                                    [ 54%]
tests/test_gc_collector.py ..                                                                                                                          [ 55%]
tests/test_graphite_bridge.py .......                                                                                                                  [ 57%]
tests/test_multiprocess.py ..........................                                                                                                  [ 66%]
tests/test_parser.py ........................                                                                                                          [ 73%]
tests/test_platform_collector.py ..                                                                                                                    [ 74%]
tests/test_process_collector.py ....                                                                                                                   [ 75%]
tests/test_twisted.py .                                                                                                                                [ 76%]
tests/test_wsgi.py .......                                                                                                                             [ 78%]
tests/openmetrics/test_exposition.py ....................                                                                                              [ 85%]
tests/openmetrics/test_parser.py .............................................                                                                         [100%]

==================================================================== 303 passed in 5.43s =====================================================================
py3.8: OK ✔ in 9.43 seconds
py3.9: install_package> python -I -m pip install --force-reinstall --no-deps /Users/chenyiqiang/WorkSpace/prometheus/client_python/.tox/.tmp/package/6/prometheus_client-0.17.1.tar.gz
py3.9: commands[0]> coverage run --parallel -m pytest
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.9.17, pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/py3.9/.pytest_cache
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 303 items

tests/test_asgi.py ssssssss                                                                                                                            [  2%]
tests/test_core.py ...................................................................................................                                 [ 35%]
tests/test_exposition.py ..........................................................                                                                    [ 54%]
tests/test_gc_collector.py ..                                                                                                                          [ 55%]
tests/test_graphite_bridge.py .......                                                                                                                  [ 57%]
tests/test_multiprocess.py ..........................                                                                                                  [ 66%]
tests/test_parser.py ........................                                                                                                          [ 73%]
tests/test_platform_collector.py ..                                                                                                                    [ 74%]
tests/test_process_collector.py ....                                                                                                                   [ 75%]
tests/test_twisted.py s                                                                                                                                [ 76%]
tests/test_wsgi.py .......                                                                                                                             [ 78%]
tests/openmetrics/test_exposition.py ....................                                                                                              [ 85%]
tests/openmetrics/test_parser.py .............................................                                                                         [100%]

=============================================================== 294 passed, 9 skipped in 4.91s ===============================================================
py3.9: OK ✔ in 7.42 seconds
py3.10: install_deps> python -I -m pip install attrs coverage pytest
py3.10: install_package> python -I -m pip install --force-reinstall --no-deps /Users/chenyiqiang/WorkSpace/prometheus/client_python/.tox/.tmp/package/7/prometheus_client-0.17.1.tar.gz
py3.10: commands[0]> coverage run --parallel -m pytest
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.10.12, pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/py3.10/.pytest_cache
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 303 items

tests/test_asgi.py ssssssss                                                                                                                            [  2%]
tests/test_core.py ...................................................................................................                                 [ 35%]
tests/test_exposition.py ..........................................................                                                                    [ 54%]
tests/test_gc_collector.py ..                                                                                                                          [ 55%]
tests/test_graphite_bridge.py .......                                                                                                                  [ 57%]
tests/test_multiprocess.py ..........................                                                                                                  [ 66%]
tests/test_parser.py ........................                                                                                                          [ 73%]
tests/test_platform_collector.py ..                                                                                                                    [ 74%]
tests/test_process_collector.py ....                                                                                                                   [ 75%]
tests/test_twisted.py s                                                                                                                                [ 76%]
tests/test_wsgi.py .......                                                                                                                             [ 78%]
tests/openmetrics/test_exposition.py ....................                                                                                              [ 85%]
tests/openmetrics/test_parser.py .............................................                                                                         [100%]

=============================================================== 294 passed, 9 skipped in 5.56s ===============================================================
py3.10: OK ✔ in 15.03 seconds
py3.11: install_package> python -I -m pip install --force-reinstall --no-deps /Users/chenyiqiang/WorkSpace/prometheus/client_python/.tox/.tmp/package/8/prometheus_client-0.17.1.tar.gz
py3.11: commands[0]> coverage run --parallel -m pytest
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/py3.11/.pytest_cache
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 303 items

tests/test_asgi.py ssssssss                                                                                                                            [  2%]
tests/test_core.py ...................................................................................................                                 [ 35%]
tests/test_exposition.py ..........................................................                                                                    [ 54%]
tests/test_gc_collector.py ..                                                                                                                          [ 55%]
tests/test_graphite_bridge.py .......                                                                                                                  [ 57%]
tests/test_multiprocess.py ..........................                                                                                                  [ 66%]
tests/test_parser.py ........................                                                                                                          [ 73%]
tests/test_platform_collector.py ..                                                                                                                    [ 74%]
tests/test_process_collector.py ....                                                                                                                   [ 75%]
tests/test_twisted.py s                                                                                                                                [ 76%]
tests/test_wsgi.py .......                                                                                                                             [ 78%]
tests/openmetrics/test_exposition.py ....................                                                                                              [ 85%]
tests/openmetrics/test_parser.py .............................................                                                                         [100%]

=============================================================== 294 passed, 9 skipped in 5.11s ===============================================================
py3.11: OK ✔ in 8.23 seconds
pypy3.8: install_deps> python -I -m pip install asgiref==3.6.0 attrs coverage pytest twisted
pypy3.8: install_package> python -I -m pip install --force-reinstall --no-deps /Users/chenyiqiang/WorkSpace/prometheus/client_python/.tox/.tmp/package/9/prometheus_client-0.17.1.tar.gz
pypy3.8: commands[0]> coverage run --parallel -m pytest
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.8.16[pypy-7.3.11-final], pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/pypy3.8/.pytest_cache
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 303 items

tests/test_asgi.py ........                                                                                                                            [  2%]
tests/test_core.py ...................................................................................................                                 [ 35%]
tests/test_exposition.py ..........................................................                                                                    [ 54%]
tests/test_gc_collector.py ss                                                                                                                          [ 55%]
tests/test_graphite_bridge.py .......                                                                                                                  [ 57%]
tests/test_multiprocess.py ..........................                                                                                                  [ 66%]
tests/test_parser.py ........................                                                                                                          [ 73%]
tests/test_platform_collector.py ..                                                                                                                    [ 74%]
tests/test_process_collector.py ....                                                                                                                   [ 75%]
tests/test_twisted.py .                                                                                                                                [ 76%]
tests/test_wsgi.py .......                                                                                                                             [ 78%]
tests/openmetrics/test_exposition.py ....................                                                                                              [ 85%]
tests/openmetrics/test_parser.py .............................................                                                                         [100%]

============================================================== 301 passed, 2 skipped in 16.41s ===============================================================
pypy3.8: OK ✔ in 39.05 seconds
py3.9-nooptionals: install_package> python -I -m pip install --force-reinstall --no-deps /Users/chenyiqiang/WorkSpace/prometheus/client_python/.tox/.tmp/package/10/prometheus_client-0.17.1.tar.gz
py3.9-nooptionals: commands[0]> coverage run --parallel -m pytest
==================================================================== test session starts =====================================================================
platform darwin -- Python 3.9.17, pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/py3.9-nooptionals/.pytest_cache
rootdir: /Users/chenyiqiang/WorkSpace/prometheus/client_python
collected 303 items

tests/test_asgi.py ssssssss                                                                                                                            [  2%]
tests/test_core.py ...................................................................................................                                 [ 35%]
tests/test_exposition.py ..........................................................                                                                    [ 54%]
tests/test_gc_collector.py ..                                                                                                                          [ 55%]
tests/test_graphite_bridge.py .......                                                                                                                  [ 57%]
tests/test_multiprocess.py ..........................                                                                                                  [ 66%]
tests/test_parser.py ........................                                                                                                          [ 73%]
tests/test_platform_collector.py ..                                                                                                                    [ 74%]
tests/test_process_collector.py ....                                                                                                                   [ 75%]
tests/test_twisted.py s                                                                                                                                [ 76%]
tests/test_wsgi.py .......                                                                                                                             [ 78%]
tests/openmetrics/test_exposition.py ....................                                                                                              [ 85%]
tests/openmetrics/test_parser.py .............................................                                                                         [100%]

=============================================================== 294 passed, 9 skipped in 4.92s ===============================================================
.pkg: _exit> python /usr/local/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py3.9-nooptionals: OK ✔ in 7.47 seconds
coverage-report: commands[0]> coverage combine
Combined data file .coverage.chenyiqiangdeMacBook-Pro.local.87495.191822
Combined data file .coverage.chenyiqiangdeMacBook-Pro.local.87460.210222
Combined data file .coverage.chenyiqiangdeMacBook-Pro.local.87471.527212
Combined data file .coverage.chenyiqiangdeMacBook-Pro.local.87506.070985
Combined data file .coverage.chenyiqiangdeMacBook-Pro.local.87443.189014
Skipping duplicate data .coverage.chenyiqiangdeMacBook-Pro.local.87451.597255
coverage-report: commands[1]> coverage report
Name                                          Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------------------
prometheus_client/__init__.py                    22     12      2      1    46%   51-67
prometheus_client/asgi.py                        19      0     10      1    97%   30->exit
prometheus_client/bridge/__init__.py              0      0      0      0   100%
prometheus_client/bridge/graphite.py             62     20     16      0    69%   25-28, 31-45, 92-94
prometheus_client/context_managers.py            54      2     10      1    95%   11-12
prometheus_client/core.py                         5      0      0      0   100%
prometheus_client/exposition.py                 217     34     80      8    84%   86, 103, 157-159, 165-173, 264-275, 301-309, 327, 383->388, 414, 419-420, 556, 593
prometheus_client/gc_collector.py                22      0      4      0   100%
prometheus_client/metrics.py                    286      4    122      4    98%   169, 202, 364, 400, 609->exit
prometheus_client/metrics_core.py               154      5     78      4    96%   54, 69, 147, 270, 304
prometheus_client/mmap_dict.py                   91      2     30      4    95%   31, 78->exit, 90, 134->exit
prometheus_client/multiprocess.py               115      3     74      2    97%   15-16, 32->exit, 70
prometheus_client/openmetrics/__init__.py         0      0      0      0   100%
prometheus_client/openmetrics/exposition.py      39      1     24      1    97%   51
prometheus_client/openmetrics/parser.py         442      0    284      4    99%   124->179, 173->178, 214->221, 337->297
prometheus_client/parser.py                     139      3     58      4    96%   73->80, 106, 173, 213
prometheus_client/platform_collector.py          32      0      8      1    98%   23->exit
prometheus_client/process_collector.py           66      4     22      4    91%   11-13, 19->exit, 34-35, 45->exit, 50->49, 84->83
prometheus_client/registry.py                   110      4     62      1    96%   13, 18, 123-124, 164->162
prometheus_client/samples.py                     31      2      4      1    91%   9, 19
prometheus_client/twisted/__init__.py             2      0      0      0   100%
prometheus_client/twisted/_exposition.py          4      0      2      0   100%
prometheus_client/utils.py                       18      1      8      1    92%   13
prometheus_client/values.py                      85      4     32      1    96%   64-65, 112, 121
-----------------------------------------------------------------------------------------
TOTAL                                          2015    101    930     43    95%
coverage-report: OK ✔ in 0.8 seconds
flake8: commands[0]> flake8 prometheus_client/ tests/ setup.py
flake8: OK ✔ in 1.85 seconds
isort: commands[0]> isort --check prometheus_client/ tests/ setup.py
isort: OK ✔ in 0.35 seconds
mypy: commands[0]> mypy --install-types --non-interactive prometheus_client/ tests/
Success: no issues found in 36 source files
  coverage-clean: OK (0.40=setup[0.14]+cmd[0.26] seconds)
  py3.8: OK (9.43=setup[3.34]+cmd[6.10] seconds)
  py3.9: OK (7.42=setup[1.90]+cmd[5.52] seconds)
  py3.10: OK (15.03=setup[8.94]+cmd[6.08] seconds)
  py3.11: OK (8.23=setup[2.23]+cmd[6.00] seconds)
  pypy3.8: OK (39.05=setup[20.25]+cmd[18.80] seconds)
  py3.9-nooptionals: OK (7.47=setup[1.95]+cmd[5.51] seconds)
  coverage-report: OK (0.79=setup[0.01]+cmd[0.41,0.37] seconds)
  flake8: OK (1.84=setup[0.01]+cmd[1.83] seconds)
  isort: OK (0.35=setup[0.01]+cmd[0.34] seconds)
  mypy: OK (0.98=setup[0.01]+cmd[0.97] seconds)
  congratulations :) (91.18 seconds)

@roidelapluie
Copy link
Member

Thank you for this.

I think this adds a lot of complexity just to remove a warning.

Since we expect this warning, why not using filters to ignore this specific warning?

…eadBody`."

This reverts commit 78fb586.

Signed-off-by: kareza <kareza@qq.com>
Signed-off-by: kareza <kareza@qq.com>
@karezachen
Copy link
Contributor Author

@roidelapluie

Thank you for your suggestion.

At first, I did plan to use filter , but I thought it wouldn't be what the project hoped for.

Using filter would indeed be more concise.

Updated.

tests/test_twisted.py Outdated Show resolved Hide resolved
Signed-off-by: kareza <kareza@qq.com>
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@csmarchbanks csmarchbanks changed the title Use _read_response_body to asyn read the body instead of readBody. Filter readBody deprecation notice in tests Sep 18, 2023
@csmarchbanks csmarchbanks merged commit 2ff5328 into prometheus:master Sep 18, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants