mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
pytest: Make directory cleanup robust against setup failures
We were triggering a second exception in the directory cleanup step by attempting to access a field that'd only be set upon entering the test code itself. That error did not contribute to the problem resolution, so now we check whether that field is set before accessing it. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
20a2e3ca6d
commit
88f425fcc5
@ -54,8 +54,13 @@ def directory(request, test_base_dir, test_name):
|
||||
yield directory
|
||||
|
||||
# This uses the status set in conftest.pytest_runtest_makereport to
|
||||
# determine whether we succeeded or failed.
|
||||
if not request.node.has_errors and request.node.rep_call.outcome == 'passed':
|
||||
# determine whether we succeeded or failed. Outcome can be None if the
|
||||
# failure occurs during the setup phase, hence the use to getattr instead
|
||||
# of accessing it directly.
|
||||
outcome = getattr(request.node, 'rep_call', None)
|
||||
failed = not outcome or request.node.has_errors or outcome != 'passed'
|
||||
|
||||
if not failed:
|
||||
shutil.rmtree(directory)
|
||||
else:
|
||||
logging.debug("Test execution failed, leaving the test directory {} intact.".format(directory))
|
||||
|
Loading…
Reference in New Issue
Block a user