Registry / testing / pytest-eventlet

pytest-eventlet

JSON →
library1.0.0pypypiunverified

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.

pip install pytest-eventlet eventlet
INSTALL
IMPORT
SIG · PYTEST-EVENTLET
P
pytest-eventlet
testingpythonv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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`.

import socket import eventlet import pytest import subprocess import sys # Save this as test_eventlet_patch.py def test_socket_is_monkey_patched(): assert eventlet.patcher.is_monkey_patched('socket'), "Socket module was not monkey-patched by eventlet!" # To run this, create a temporary file and invoke pytest # Example of how to run this from a script: # with open('test_eventlet_patch.py', 'w') as f: # f.write(''' # import socket # import eventlet # def test_socket_is_monkey_patched(): # assert eventlet.patcher.is_monkey_patched('socket'), "Socket module was not monkey-patched by eventlet!" # ''') # result = subprocess.run([sys.executable, '-m', 'pytest', 'test_eventlet_patch.py'], capture_output=True, text=True) # print(result.stdout) # print(result.stderr) # assert "1 passed" in result.stdout # assert "Socket module was not monkey-patched" not in result.stdout # Ensure it passed
Debug
Known issues
gotchapytest-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.
fix
Ensure `eventlet` is installed: `pip install pytest-eventlet eventlet`.
affects: 1.0.0
gotchaMonkey-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.
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.
affects: 1.0.0
gotchaThe `--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.
fix
Remove `--no-eventlet` from your pytest command if you intend for eventlet patching to be active.
affects: 1.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'eventlet'
The `pytest-eventlet` plugin was installed, but the `eventlet` library itself is missing.
fix
Install the `eventlet` library: `pip install eventlet`.
AssertionError: Socket module was not monkey-patched by eventlet!
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.
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`.
Tests hanging indefinitely or timing out.
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).
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`.
Upgrade
Version history
1.0.0latest on PyPI · released Oct 4, 2021
Audit
Dependencies
pytestrequiredRequired runtime environment for a pytest plugin.
eventletrequiredCore library whose monkey-patching behavior is managed by the plugin; required for the plugin to have any effect.
Agent activity
4 hits · last 30 days
node
4
Resources
pytest-eventlet — pip install pytest-eventlet · libregistry