diff --git a/eventlet/green/subprocess.py b/eventlet/green/subprocess.py index d639cd57c6..50f0bc25c3 100644 --- a/eventlet/green/subprocess.py +++ b/eventlet/green/subprocess.py @@ -133,3 +133,9 @@ def patched_function(function): __patched__.append('check_output') check_output = patched_function(subprocess_orig.check_output) del patched_function + +# Keep exceptions identity. +# https://github.com/eventlet/eventlet/issues/413 +subprocess_imported = sys.modules['subprocess'] +CalledProcessError = subprocess_imported.CalledProcessError +del subprocess_imported diff --git a/tests/isolated/subprocess_exception_identity.py b/tests/isolated/subprocess_exception_identity.py new file mode 100644 index 0000000000..bc14f43ea3 --- /dev/null +++ b/tests/isolated/subprocess_exception_identity.py @@ -0,0 +1,12 @@ +__test__ = False + +if __name__ == '__main__': + import subprocess as original + from eventlet.green import subprocess as green + + cases = ( + 'CalledProcessError', + ) + for c in cases: + assert getattr(green, c) is getattr(original, c), c + print('pass') diff --git a/tests/subprocess_test.py b/tests/subprocess_test.py index d18c62395c..9040919b22 100644 --- a/tests/subprocess_test.py +++ b/tests/subprocess_test.py @@ -93,3 +93,9 @@ def test_check_call_without_timeout_works(): stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) + + +def test_exception_identity(): + # https://github.com/eventlet/eventlet/issues/413 + # green module must keep exceptions classes as stdlib version + tests.run_isolated('subprocess_exception_identity.py')