Browse Source

pytest: Warnings

Signed-off-by: Michał Górny <>
Michał Górny 2 months ago
No known key found for this signature in database GPG Key ID: 639ADAE2329E240E
  1. 53


@ -208,6 +208,59 @@ mocker dev-python/pytest-mock
=================================== ====================================
pytest captures all warnings from the test suite by default, and prints
a summary of them at the end of the test suite run::
=============================== warnings summary ===============================
asgiref/ 1 warning
tests/ 5 warnings
tests/ 12 warnings
tests/ 1 warning
/tmp/asgiref/asgiref/ DeprecationWarning: There is no current event loop
self.main_event_loop = asyncio.get_event_loop()
However, some projects go further and use ``filterwarnings`` option
to make (some) warnings fatal::
==================================== ERRORS ====================================
_____________________ ERROR collecting tests/ ______________________
tests/ in <module>
class ASGITest(TestCase):
tests/ in ASGITest
async def test_wrapped_case_is_collected(self):
asgiref/ in __init__
self.main_event_loop = asyncio.get_event_loop()
E DeprecationWarning: There is no current event loop
=========================== short test summary info ============================
ERROR tests/ - DeprecationWarning: There is no current event loop
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.13s ===============================
Unfortunately, this frequently means that warnings coming from
a dependency trigger test failures in other packages. Since making
warnings fatal is relatively common in the Python world, it is
recommended to:
1. Fix warnings in Python packages whenever possible, even if they
are not fatal to the package itself.
2. Do not enable new Python implementations if they trigger any new
warnings in the package.
If the warnings come from issues in the package's test suite rather than
the installed code, it is acceptable to make them non-fatal. This can
be done either through removing the ``filterwarnings`` key from
``setup.cfg``, or adding an ignore entry. For example, the following
setting ignores ``DeprecationWarning`` in ``test`` directory::
filterwarnings =
.. _custom pytest markers:
.. _pytest-runner: