Workaround for cmdexec bug on Windows

This bug fails the entire pytest suite when executed with the
--lsof option in Python 2 on Windows.
This commit is contained in:
Bruno Oliveira 2015-07-24 17:52:56 -03:00
parent b84fcbc85e
commit 4f1ae8c45e
2 changed files with 9 additions and 2 deletions

View File

@ -15,7 +15,13 @@ class LsofFdLeakChecker(object):
def _exec_lsof(self):
pid = os.getpid()
#return py.process.cmdexec("lsof -Ffn0 -p %d" % pid)
return py.process.cmdexec("lsof -p %d" % pid)
try:
return py.process.cmdexec("lsof -p %d" % pid)
except UnicodeDecodeError:
# cmdexec may raise UnicodeDecodeError on Windows systems
# with locale other than english:
# https://bitbucket.org/pytest-dev/py/issues/66
return ''
def _parse_lsof_output(self, out):
def isopen(line):

View File

@ -651,7 +651,8 @@ def lsof_check():
pid = os.getpid()
try:
out = py.process.cmdexec("lsof -p %d" % pid)
except py.process.cmdexec.Error:
except (py.process.cmdexec.Error, UnicodeDecodeError):
# about UnicodeDecodeError, see note on conftest.py
pytest.skip("could not run 'lsof'")
yield
out2 = py.process.cmdexec("lsof -p %d" % pid)