You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following code and I'm curious about what I'm doing wrong. It seems that for async functions the warnings are not captured.
The code is as following
# content of test_show_warnings.pyimportwarningsdefapi_v1_for_sync():
warnings.warn(UserWarning("[sync] api v1, should use functions from v2"))
return1defapi_v1_for_async():
warnings.warn(UserWarning("[async] api v1, should use functions from v2"))
return1deftest_sync():
assertapi_v1_for_sync() ==1asyncdeftest_async():
assertapi_v1_for_async() ==1
And when running the test I would assume that both warnings are captured. Unfortunately only the sync warnings shows.
========================================= test session starts ==========================================
platform darwin -- Python 3.9.2, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /Users/rick/.local/share/virtualenvs/mock-qxkUTm3B/bin/python
cachedir: .pytest_cache
rootdir: /private/tmp/mock
plugins: cov-2.11.1, aiohttp-0.3.0, mock-3.5.1
collected 2 items
test_warning.py::test_sync PASSED [ 50%]
test_warning.py::test_async PASSED [100%]
=========================================== warnings summary ===========================================
test_warning.py::test_sync
/private/tmp/mock/test_warning.py:6: UserWarning: [sync] api v1, should use functions from v2
warnings.warn(UserWarning("[sync] api v1, should use functions from v2"))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
===================================== 2 passed, 1 warning in 0.02s =====================================
When I change the async test to run synchrounous both warnings show up.
=========================================== warnings summary ===========================================
test_warning.py::test_sync
/private/tmp/mock/test_warning.py:6: UserWarning: [sync] api v1, should use functions from v2
warnings.warn(UserWarning("[sync] api v1, should use functions from v2"))
test_warning.py::test_async
/private/tmp/mock/test_warning.py:10: UserWarning: [async] api v1, should use functions from v2
warnings.warn(UserWarning("[async] api v1, should use functions from v2"))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
==================================== 2 passed, 2 warnings in 0.01s =====================================
Is this expected behaviour, is async not (well) supported for pytest or am I missing something.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi All,
I have the following code and I'm curious about what I'm doing wrong. It seems that for async functions the warnings are not captured.
The code is as following
And when running the test I would assume that both warnings are captured. Unfortunately only the sync warnings shows.
When I change the async test to run synchrounous both warnings show up.
Is this expected behaviour, is async not (well) supported for pytest or am I missing something.
Beta Was this translation helpful? Give feedback.
All reactions