From eac49d80bbdb2245173f46d4cf3e1f19b33f5462 Mon Sep 17 00:00:00 2001 From: Sergey Shepelev Date: Sun, 14 May 2017 13:31:47 +0300 Subject: [PATCH] green.subprocess: keep CalledProcessError identity https://github.com/eventlet/eventlet/issues/413 --- eventlet/green/subprocess.py | 4 ++++ tests/subprocess_test.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/eventlet/green/subprocess.py b/eventlet/green/subprocess.py index d639cd5..96adff5 100644 --- a/eventlet/green/subprocess.py +++ b/eventlet/green/subprocess.py @@ -133,3 +133,7 @@ if hasattr(subprocess_orig, 'check_output'): __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 +CalledProcessError = subprocess_orig.CalledProcessError diff --git a/tests/subprocess_test.py b/tests/subprocess_test.py index d18c623..572d386 100644 --- a/tests/subprocess_test.py +++ b/tests/subprocess_test.py @@ -93,3 +93,13 @@ 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 + cases = ( + 'CalledProcessError', + ) + for c in cases: + assert getattr(subprocess, c) is getattr(original_subprocess, c), c