getlogbook / logbook

A cool logging replacement for Python.
http://logbook.readthedocs.org
Other
1.48k stars 165 forks source link

The package falls apart if contextvars are installed #309

Closed mgorny closed 1 year ago

mgorny commented 4 years ago

If contextvars happen to be installed on the system, the package seems to stop working completely. Most of the tests are failing, and some are just hanging. I've had to use pytest-timeout plugin to get the suite to finish:

tests/test_asyncio.py .                                                  [  0%]
tests/test_ci.py ss                                                      [  1%]
tests/test_deadlock.py .                                                 [  1%]
tests/test_file_handler.py .F..FFFFFFFF................FFFF              [ 16%]
tests/test_fingers_crossed_handler.py ..FFFF                             [ 19%]
tests/test_flags.py FF                                                   [ 20%]
tests/test_groups.py FF                                                  [ 21%]
tests/test_handler_errors.py FF.                                         [ 23%]
tests/test_handlers.py FFFFFFFFFFF                                       [ 28%]
tests/test_helpers.py ..                                                 [ 29%]
tests/test_log_record.py FFFFFFFFFF                                      [ 33%]
tests/test_logbook.py FF.                                                [ 35%]
tests/test_logger.py ...                                                 [ 36%]
tests/test_logging_api.py FFFF.FFFFFFFF                                  [ 42%]
tests/test_logging_compat.py FFFF                                        [ 44%]
tests/test_logging_times.py FFFF.                                        [ 46%]
tests/test_mail_handler.py FFFFFF.                                       [ 50%]
tests/test_more.py F.F...FFFsss                                          [ 55%]
tests/test_nteventlog_handler.py s                                       [ 56%]
tests/test_null_handler.py FFFFFF                                        [ 59%]
tests/test_processors.py FFFF                                            [ 61%]
tests/test_queues.py FFFF.FF...F...                                      [ 67%]
tests/test_syslog_handler.py .FFFFFFFFFFF                                [ 73%]
tests/test_test_handler.py FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF                [ 87%]
tests/test_ticketing.py F                                                [ 87%]
tests/test_unicode.py FFFFFFF                                            [ 91%]
tests/test_utils.py ...................                                  [100%]

Full output: 36.txt

Easy repro:

diff --git a/tox.ini b/tox.ini
index 7c21509..91a862f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,6 +8,8 @@ whitelist_externals =
 deps =
     py{27}: mock
     pytest
+    pytest-timeout
+    contextvars
     speedups: Cython
 setenv =
     !speedups: DISABLE_LOGBOOK_CEXT=1
@@ -21,7 +23,7 @@ commands =
     !speedups: {envpython} -c "from logbook.base import _has_speedups; exit(1 if _has_speedups else 0)"

     {envpython} {toxinidir}/scripts/test_setup.py
-    py.test {toxinidir}/tests
+    py.test --timeout=30 {toxinidir}/tests

 [testenv:py37-docs]
 deps =
RazerM commented 3 years ago

The contextvars backport on PyPI does not support asyncio:

Important: at this moment this package does not provide an asyncio event loop with PEP 567 support yet. Stay tuned for updates.

If you disable test_asyncio_context_management, then the test suite works again.