Browse Source

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>
htlc_accepted_hook
Christian Decker 6 years ago
committed by neil saitug
parent
commit
88f425fcc5
  1. 9
      tests/fixtures.py

9
tests/fixtures.py

@ -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…
Cancel
Save