[exception handling] Fix case the current working directory (CWD) gets deleted during testing.
Fixes #1235.
This commit is contained in:
parent
70fdab4cfa
commit
09d163aa3a
1
AUTHORS
1
AUTHORS
|
@ -69,6 +69,7 @@ Mark Abramowitz
|
||||||
Markus Unterwaditzer
|
Markus Unterwaditzer
|
||||||
Martijn Faassen
|
Martijn Faassen
|
||||||
Martin Prusse
|
Martin Prusse
|
||||||
|
Martin K. Scherer
|
||||||
Matt Bachmann
|
Matt Bachmann
|
||||||
Michael Aquilina
|
Michael Aquilina
|
||||||
Michael Birtwell
|
Michael Birtwell
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
* Fix exception visualization in case the current working directory (CWD) gets
|
||||||
|
deleted during testing. Fixes (`#1235`). Thanks `@bukzor` for reporting. PR by
|
||||||
|
`@marscher`. Thanks `@nicoddemus` for his help.
|
||||||
|
|
||||||
.. _#1580: https://github.com/pytest-dev/pytest/issues/1580
|
.. _#1580: https://github.com/pytest-dev/pytest/issues/1580
|
||||||
|
|
||||||
.. _@graingert: https://github.com/graingert
|
.. _@graingert: https://github.com/graingert
|
||||||
|
|
|
@ -2,7 +2,6 @@ import sys
|
||||||
from inspect import CO_VARARGS, CO_VARKEYWORDS
|
from inspect import CO_VARARGS, CO_VARKEYWORDS
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
|
||||||
builtin_repr = repr
|
builtin_repr = repr
|
||||||
|
|
||||||
reprlib = py.builtin._tryimport('repr', 'reprlib')
|
reprlib = py.builtin._tryimport('repr', 'reprlib')
|
||||||
|
@ -35,12 +34,16 @@ class Code(object):
|
||||||
def path(self):
|
def path(self):
|
||||||
""" return a path object pointing to source code (note that it
|
""" return a path object pointing to source code (note that it
|
||||||
might not point to an actually existing file). """
|
might not point to an actually existing file). """
|
||||||
|
try:
|
||||||
p = py.path.local(self.raw.co_filename)
|
p = py.path.local(self.raw.co_filename)
|
||||||
# maybe don't try this checking
|
# maybe don't try this checking
|
||||||
if not p.check():
|
if not p.check():
|
||||||
|
raise OSError("py.path check failed.")
|
||||||
|
except OSError:
|
||||||
# XXX maybe try harder like the weird logic
|
# XXX maybe try harder like the weird logic
|
||||||
# in the standard lib [linecache.updatecache] does?
|
# in the standard lib [linecache.updatecache] does?
|
||||||
p = self.raw.co_filename
|
p = self.raw.co_filename
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -403,7 +403,13 @@ class Node(object):
|
||||||
else:
|
else:
|
||||||
style = "long"
|
style = "long"
|
||||||
|
|
||||||
return excinfo.getrepr(funcargs=True,
|
try:
|
||||||
|
os.getcwd()
|
||||||
|
abspath = False
|
||||||
|
except OSError:
|
||||||
|
abspath = True
|
||||||
|
|
||||||
|
return excinfo.getrepr(funcargs=True, abspath=abspath,
|
||||||
showlocals=self.config.option.showlocals,
|
showlocals=self.config.option.showlocals,
|
||||||
style=style, tbfilter=tbfilter)
|
style=style, tbfilter=tbfilter)
|
||||||
|
|
||||||
|
|
|
@ -925,3 +925,14 @@ def test_repr_traceback_with_unicode(style, encoding):
|
||||||
repr_traceback = formatter.repr_traceback(e_info)
|
repr_traceback = formatter.repr_traceback(e_info)
|
||||||
assert repr_traceback is not None
|
assert repr_traceback is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_cwd_deleted(testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
def test(tmpdir):
|
||||||
|
tmpdir.chdir()
|
||||||
|
tmpdir.remove()
|
||||||
|
assert False
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest()
|
||||||
|
result.stdout.fnmatch_lines(['* 1 failed in *'])
|
||||||
|
assert 'INTERNALERROR' not in result.stdout.str() + result.stderr.str()
|
||||||
|
|
Loading…
Reference in New Issue