{"id":9245,"library":"pytest-eventlet","title":"pytest-eventlet","description":"pytest-eventlet is a pytest plugin that automatically applies the eventlet monkey-patch to your test suite. It simplifies testing eventlet-dependent code by ensuring the environment is correctly configured. The current version is 1.0.0, and as an initial release, its cadence is currently low but stable.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/nameko/pytest-eventlet","tags":["pytest","plugin","eventlet","concurrency","monkey-patch","testing"],"install":[{"cmd":"pip install pytest-eventlet eventlet","lang":"bash","label":"Install plugin and eventlet"}],"dependencies":[{"reason":"Required runtime environment for a pytest plugin.","package":"pytest","optional":false},{"reason":"Core library whose monkey-patching behavior is managed by the plugin; required for the plugin to have any effect.","package":"eventlet","optional":false}],"imports":[],"quickstart":{"code":"import socket\nimport eventlet\nimport pytest\nimport subprocess\nimport sys\n\n# Save this as test_eventlet_patch.py\ndef test_socket_is_monkey_patched():\n    assert eventlet.patcher.is_monkey_patched('socket'), \"Socket module was not monkey-patched by eventlet!\"\n\n# To run this, create a temporary file and invoke pytest\n# Example of how to run this from a script:\n# with open('test_eventlet_patch.py', 'w') as f:\n#     f.write('''\n# import socket\n# import eventlet\n# def test_socket_is_monkey_patched():\n#     assert eventlet.patcher.is_monkey_patched('socket'), \"Socket module was not monkey-patched by eventlet!\"\n#     ''')\n# result = subprocess.run([sys.executable, '-m', 'pytest', 'test_eventlet_patch.py'], capture_output=True, text=True)\n# print(result.stdout)\n# print(result.stderr)\n# assert \"1 passed\" in result.stdout\n# assert \"Socket module was not monkey-patched\" not in result.stdout # Ensure it passed\n","lang":"python","description":"Create a file named `test_eventlet_patch.py`. With `pytest-eventlet` and `eventlet` installed, simply running `pytest` will automatically apply the monkey-patch. This quickstart test verifies that the `socket` module has indeed been patched by `eventlet`."},"warnings":[{"fix":"Ensure `eventlet` is installed: `pip install pytest-eventlet eventlet`.","message":"pytest-eventlet relies on the `eventlet` library being installed alongside it. If `eventlet` is not present, the plugin will load without error but will not apply any monkey-patches, leading to tests that silently run without eventlet's concurrency features.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Isolate test runs by using separate virtual environments or explicitly disabling conflicting plugins. For `pytest-eventlet`, you can use the `--no-eventlet` flag to temporarily disable its patching.","message":"Monkey-patching, especially global patching like eventlet's, can conflict with other concurrency libraries (e.g., gevent, asyncio) or testing frameworks that also modify standard library modules. Running tests with multiple such plugins enabled can lead to unpredictable behavior or crashes.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Remove `--no-eventlet` from your pytest command if you intend for eventlet patching to be active.","message":"The `--no-eventlet` command-line flag disables the eventlet monkey-patch. If your tests are unexpectedly failing due to blocking I/O or other eventlet-related issues, double-check that this flag is not inadvertently enabled, as it will prevent the plugin from doing its job.","severity":"gotcha","affected_versions":"1.0.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the `eventlet` library: `pip install eventlet`.","cause":"The `pytest-eventlet` plugin was installed, but the `eventlet` library itself is missing.","error":"ModuleNotFoundError: No module named 'eventlet'"},{"fix":"Verify `eventlet` is installed. Ensure `pytest-eventlet` is in your environment and not disabled by a pytest config or command-line flag like `--no-eventlet`.","cause":"Your test expects eventlet's monkey-patching to be active, but it wasn't applied. This can happen if `eventlet` is not installed, the plugin is not active, or the `--no-eventlet` flag was used.","error":"AssertionError: Socket module was not monkey-patched by eventlet!"},{"fix":"Confirm `eventlet` patching is active using a diagnostic test (like the quickstart example). Review your application code for blocking operations that need to be made cooperative with `eventlet`.","cause":"This often indicates that `eventlet` monkey-patching is either not active, or the code under test is not written to be cooperative with eventlet (e.g., using blocking calls without yielding).","error":"Tests hanging indefinitely or timing out."}]}