Skip to content

Commit 12c8770

Browse files
committed
Add a test with native oserror.
1 parent 5bd4af8 commit 12c8770

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/test_pickle_exception.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from traceback import format_exception
23

34
try:
@@ -345,3 +346,20 @@ def test_oserror_simple():
345346
assert exc.errno == 13
346347
assert exc.strerror == 'Permission denied'
347348
assert exc.__traceback__ is not None
349+
350+
351+
def test_real_oserror():
352+
try:
353+
os.open('non-existing-file', os.O_RDONLY)
354+
except Exception as e:
355+
exc = e
356+
else:
357+
pytest.fail('os.open should have raised an OSError')
358+
359+
str_output = str(exc)
360+
tblib.pickling_support.install(exc)
361+
exc = pickle.loads(pickle.dumps(exc))
362+
363+
assert isinstance(exc, OSError)
364+
assert exc.errno == 2
365+
assert str_output == str(exc)

0 commit comments

Comments
 (0)