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

test_asyncio_context_management[True] fails w/ py3.7+ if gevent is installed #310

Open
mgorny opened this issue Apr 26, 2020 · 2 comments
Open

Comments

@mgorny
Copy link

mgorny commented Apr 26, 2020

==================================================================== FAILURES =====================================================================
______________________________________________________ test_asyncio_context_management[True] ______________________________________________________

logger = <logbook.base.Logger object at 0x7f6fd2ce90d0>

    @pytest.mark.skipif(not has_contextvars, reason="Contexvars not available")
    def test_asyncio_context_management(logger):
        h1 = logbook.TestHandler()
        h2 = logbook.TestHandler()
    
        async def task(handler, msg):
            for _ in range(ITERATIONS):
                with handler.contextbound():
                    logger.info(msg)
    
                await asyncio.sleep(0)  # allow for context switch
    
        asyncio.get_event_loop().run_until_complete(asyncio.gather(task(h1, 'task1'), task(h2, 'task2')))
    
>       assert len(h1.records) == ITERATIONS
E       assert 200 == 100
E        +  where 200 = len([<logbook.base.LogRecord object at 0x7f6fd2ce2bd0>, <logbook.base.LogRecord object at 0x7f6fd2ce2e90>, <logbook.base.L...6fd2ce2cd0>, <logbook.base.LogRecord object at 0x7f6fd2ce2f50>, <logbook.base.LogRecord object at 0x7f6fd2ce2d90>, ...])
E        +    where [<logbook.base.LogRecord object at 0x7f6fd2ce2bd0>, <logbook.base.LogRecord object at 0x7f6fd2ce2e90>, <logbook.base.L...6fd2ce2cd0>, <logbook.base.LogRecord object at 0x7f6fd2ce2f50>, <logbook.base.LogRecord object at 0x7f6fd2ce2d90>, ...] = <logbook.handlers.TestHandler object at 0x7f6fd2ce21d0>.records

tests/test_asyncio.py:23: AssertionError

To repro:

diff --git a/tox.ini b/tox.ini
index 7c21509..79be9f5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -7,6 +7,7 @@ whitelist_externals =
     rm
 deps =
     py{27}: mock
+    gevent
     pytest
     speedups: Cython
 setenv =

@mgorny mgorny changed the title test_asyncio_context_management[True] fails if gevent is installed test_asyncio_context_management[True] fails w/ py3.7+ if gevent is installed Apr 26, 2020
@mgorny
Copy link
Author

mgorny commented Apr 26, 2020

Oh, forgot to mention it happens with py3.7 and py3.8, not py3.6.

@matan129
Copy link
Contributor

matan129 commented Jan 12, 2021

[I was the original contributor of the asyncio feature in Logbook - seeing this issue by pure chance.]

This probably happens because gevent and the builtin contextvars module (Python 3.7+) aren't compatible.
This explains why the tests succeed in Python 3.6, since the test is skipped in that version.

It's an easy fix IMHO, we just have to consider gevent (or even use gevent.contextvars) in concurrency.py.

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

No branches or pull requests

2 participants