Skip to content
Permalink
Browse files
Add "--keep-failed-test-dir" option that only keeps the ccm test dire…
…ctory for failed tests

 patch by Mick Semb Wever; reviewed by Brandon Williams
  • Loading branch information
michaelsembwever committed Aug 24, 2020
1 parent 79c0120 commit cefddf845d63919c6e7b5efa35b28fe7a5ad1142
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
@@ -81,6 +81,9 @@ def pytest_addoption(parser):
parser.addoption("--keep-test-dir", action="store_true", default=False,
help="Do not remove/cleanup the test ccm cluster directory and it's artifacts "
"after the test completes")
parser.addoption("--keep-failed-test-dir", action="store_true", default=False,
help="Do not remove/cleanup the test ccm cluster directory and it's artifacts "
"after the test fails")
parser.addoption("--enable-jacoco-code-coverage", action="store_true", default=False,
help="Enable JaCoCo Code Coverage Support")
parser.addoption("--upgrade-version-selection", action="store", default="indev",
@@ -285,6 +288,13 @@ def fixture_dtest_create_cluster_func():
"""
return DTestSetup.create_ccm_cluster

@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
return rep

@pytest.fixture(scope='function', autouse=False)
def fixture_dtest_setup(request,
dtest_config,
@@ -336,7 +346,7 @@ def fixture_dtest_setup(request,
except Exception as e:
logger.error("Error saving log:", str(e))
finally:
dtest_setup.cleanup_cluster()
dtest_setup.cleanup_cluster(request)


#Based on https://bugs.python.org/file25808/14894.patch
@@ -20,6 +20,7 @@ def __init__(self):
self.execute_upgrade_tests_only = False
self.disable_active_log_watching = False
self.keep_test_dir = False
self.keep_failed_test_dir = False
self.enable_jacoco_code_coverage = False
self.jemalloc_path = find_libjemalloc()

@@ -42,6 +43,7 @@ def setup(self, request):
self.execute_upgrade_tests_only = request.config.getoption("--execute-upgrade-tests-only")
self.disable_active_log_watching = request.config.getoption("--disable-active-log-watching")
self.keep_test_dir = request.config.getoption("--keep-test-dir")
self.keep_failed_test_dir = request.config.getoption("--keep-failed-test-dir")
self.enable_jacoco_code_coverage = request.config.getoption("--enable-jacoco-code-coverage")

def get_version_from_build(self):
@@ -347,9 +347,9 @@ def stop_active_log_watch(self):
"""
self.log_watch_thread.join(timeout=60)

def cleanup_cluster(self):
def cleanup_cluster(self, request):
with log_filter('cassandra'): # quiet noise from driver when nodes start going down
if self.dtest_config.keep_test_dir:
if self.dtest_config.keep_test_dir or (self.dtest_config.keep_failed_test_dir and request.node.rep_call.failed):
self.cluster.stop(gently=self.dtest_config.enable_jacoco_code_coverage)
else:
# when recording coverage the jvm has to exit normally

0 comments on commit cefddf8

Please sign in to comment.