Try new way to avoid pytest io errors

This commit is contained in:
shortcutme 2019-11-27 03:03:22 +01:00
parent 8b6f221e22
commit 777486a5be
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 31 additions and 3 deletions

View File

@ -413,8 +413,36 @@ def crypt_bitcoin_lib(request, monkeypatch):
CryptBitcoin.loadLib(request.param)
return CryptBitcoin
# Workaround for pytest>=0.4.1 bug when logging in atexit handlers (I/O operation on closed file)
@pytest.fixture(scope='session', autouse=True)
def disableLog():
def workaroundPytestLogError():
# Workaround for pytest bug when logging in atexit/post-fixture handlers (I/O operation on closed file)
import _pytest.capture
write_original = _pytest.capture.EncodedFile.write
def write_patched(obj, *args, **kwargs):
try:
write_original(obj, *args, **kwargs)
except ValueError as err:
if str(err) == "I/O operation on closed file":
pass
else:
raise err
def flush_patched(obj, *args, **kwargs):
try:
obj.buffer.flush(*args, **kwargs)
except ValueError as err:
if str(err).startswith("I/O operation on closed file"):
pass
else:
raise err
_pytest.capture.EncodedFile.write = write_patched
_pytest.capture.EncodedFile.flush = flush_patched
workaroundPytestLogError()
yield None # Wait until all test done
logging.getLogger('').setLevel(logging.getLevelName(logging.CRITICAL))