pytest-eventlet

1.0.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Quickstart

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

view raw JSON →