Fix unraisable exception in test_examples

The way we called subprocess.Popen, it looks like we didn't close all
the pipes; this PR addresses the warning that pytest generates when
running the examples.

In addition, we toggle the pytest setting to error on any warning
This commit is contained in:
Ogi Moore 2021-05-30 21:29:24 -07:00
parent d72be799d7
commit c7675ca8bb
2 changed files with 29 additions and 30 deletions

View File

@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import
from collections import namedtuple from collections import namedtuple
from pyqtgraph import Qt from pyqtgraph import Qt
import errno import errno
import time
import importlib import importlib
import itertools import itertools
import pytest import pytest
import os, sys import os, sys
import platform import platform
import subprocess import subprocess
import time
from argparse import Namespace from argparse import Namespace
if __name__ == "__main__" and (__package__ is None or __package__==''): if __name__ == "__main__" and (__package__ is None or __package__==''):
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -143,13 +140,11 @@ conditionalExamples = {
] ]
) )
def testExamples(frontend, f): def testExamples(frontend, f):
# runExampleFile(f[0], f[1], sys.executable, frontend)
name, file = f name, file = f
global path global path
fn = os.path.join(path, file) fn = os.path.join(path, file)
os.chdir(path) os.chdir(path)
sys.stdout.write("{} ".format(name)) sys.stdout.write(f"{name}")
sys.stdout.flush() sys.stdout.flush()
import1 = "import %s" % frontend if frontend != '' else '' import1 = "import %s" % frontend if frontend != '' else ''
import2 = os.path.splitext(os.path.split(fn)[1])[0] import2 = os.path.splitext(os.path.split(fn)[1])[0]
@ -172,24 +167,19 @@ except:
raise raise
""".format(import1, import2) """.format(import1, import2)
if sys.platform.startswith('win'): process = subprocess.Popen([sys.executable],
process = subprocess.Popen([sys.executable], stdin=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
stderr=subprocess.PIPE, stdout=subprocess.PIPE,
stdout=subprocess.PIPE) text=True)
else: process.stdin.write(code)
process = subprocess.Popen(['exec %s -i' % (sys.executable)],
shell=True,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
process.stdin.write(code.encode('UTF-8'))
process.stdin.close() process.stdin.close()
output = '' output = ''
fail = False fail = False
while True: while True:
try: try:
c = process.stdout.read(1).decode() c = process.stdout.read(1)
except IOError as err: except IOError as err:
if err.errno == errno.EINTR: if err.errno == errno.EINTR:
# Interrupted system call; just try again. # Interrupted system call; just try again.
@ -197,7 +187,6 @@ except:
else: else:
raise raise
output += c output += c
if output.endswith('test complete'): if output.endswith('test complete'):
break break
if output.endswith('test failed'): if output.endswith('test failed'):
@ -210,16 +199,25 @@ except:
if time.time() - start > 2.0 and not killed: if time.time() - start > 2.0 and not killed:
process.kill() process.kill()
killed = True killed = True
#res = process.communicate()
res = (process.stdout.read(), process.stderr.read()) stdout, stderr = (process.stdout.read(), process.stderr.read())
process.stdout.close()
process.stderr.close()
if (fail or if (fail or
'exception' in res[1].decode().lower() or 'exception' in stderr.lower() or
'error' in res[1].decode().lower()): 'error' in stderr.lower()):
print(res[0].decode()) if (not fail
print(res[1].decode()) and name == "RemoteGraphicsView"
pytest.fail("{}\n{}\nFailed {} Example Test Located in {} " and "pyqtgraph.multiprocess.remoteproxy.ClosedError" in stderr):
.format(res[0].decode(), res[1].decode(), name, file), # This test can intermittently fail when the subprocess is killed
pytrace=False) return None
print(stdout)
print(stderr)
pytest.fail(
f"{stdout}\n{stderr}\nFailed {name} Example Test Located in {file}",
pytrace=False
)
if __name__ == "__main__": if __name__ == "__main__":
pytest.cmdline.main() pytest.cmdline.main()

View File

@ -7,6 +7,7 @@ xvfb_args=-ac +extension GLX +render
faulthandler_timeout = 60 faulthandler_timeout = 60
filterwarnings = filterwarnings =
error
# re-enable standard library warnings # re-enable standard library warnings
once::DeprecationWarning once::DeprecationWarning
once::PendingDeprecationWarning once::PendingDeprecationWarning