Skip to content
Permalink
Browse files
Ninja fix all occurences of non-existent self.fail to pytest.fail
  • Loading branch information
driftx committed Jun 24, 2021
1 parent 7c42b70 commit bca1834dc7075ced5ebaeda15afcf691bcd30ab1
Showing 16 changed files with 29 additions and 28 deletions.
@@ -845,7 +845,7 @@ def test_permissions_caching(self):
def check_caching(attempt=0):
attempt += 1
if attempt > 3:
self.fail("Unable to verify cache expiry in 3 attempts, failing")
pytest.fail("Unable to verify cache expiry in 3 attempts, failing")

logger.debug("Attempting to verify cache expiry, attempt #{i}".format(i=attempt))
# grant SELECT to cathy
@@ -866,7 +866,7 @@ def check_caching(attempt=0):
check_caching(attempt)
else:
# legit failure
self.fail("Expecting query to raise an exception, but nothing was raised.")
pytest.fail("Expecting query to raise an exception, but nothing was raised.")
except Unauthorized as e:
assert re.search("User cathy has no SELECT permission on <table ks.cf> or any of its parents", str(e))

@@ -2742,7 +2742,7 @@ def test_authentication_handle_unavailable(self):

try:
self.patient_exclusive_cql_connection(node0, timeout=2, user='cassandra', password='cassandra')
self.fail("Expected login attempt to raise an exception.")
pytest.fail("Expected login attempt to raise an exception.")
except NoHostAvailable as e:
# From driver
assert isinstance(list(e.errors.values())[0], AuthenticationFailed)
@@ -2781,7 +2781,7 @@ def test_authentication_through_cache_handle_unavailable(self):

try:
self.patient_exclusive_cql_connection(node0, timeout=2, user='cassandra', password='cassandra')
self.fail("Expected login attempt to raise an exception.")
pytest.fail("Expected login attempt to raise an exception.")
except NoHostAvailable as e:
# From driver
assert isinstance(list(e.errors.values())[0], AuthenticationFailed)
@@ -530,7 +530,7 @@ def _fail_and_print_sets(self, rd_one, rd_two, msg):
print('Set Two:')
for idx_two in rd_two:
print(' {},{},{},{}'.format(idx_two.name, idx_two.completed, idx_two.offset, idx_two.log_name))
self.fail(msg)
pytest.fail(msg)

def _init_new_loading_node(self, ks_name, create_stmt, use_thrift=False):
loading_node = Node(
@@ -1,5 +1,6 @@
import os
import logging
import pytest

from dtest import Tester, create_ks, create_cf

@@ -31,7 +32,7 @@ def test_cfid(self):
try:
cfs = os.listdir(node1.get_path() + "/data0/ks")
except OSError:
self.fail("Path to sstables not valid.")
pytest.fail("Path to sstables not valid.")

# check that there are 5 unique directories
assert len(cfs) == 5
@@ -189,7 +189,7 @@ def test_sstable_deletion(self, strategy):
assert not "Data" in afile, afile

except OSError:
self.fail("Path to sstables not valid.")
pytest.fail("Path to sstables not valid.")

@pytest.mark.parametrize("strategy", ['DateTieredCompactionStrategy'])
def test_dtcs_deletion(self, strategy):
@@ -2532,7 +2532,7 @@ def test_login_authenticates_correct_user(self):
if expected_error in err_line:
break
else:
self.fail("Did not find expected error '{}' in "
pytest.fail("Did not find expected error '{}' in "
"cqlsh stderr output: {}".format(expected_error,
'\n'.join(err_lines)))

@@ -149,7 +149,7 @@ def _wait_for_view_build_start(self, session, ks, view, wait_minutes=2):

elapsed = (time.time() - start) / 60
if elapsed > wait_minutes:
self.fail("The MV build hasn't started in 2 minutes.")
pytest.fail("The MV build hasn't started in 2 minutes.")

def _insert_data(self, session):
# insert data
@@ -1859,10 +1859,10 @@ def check_trace_events(self, trace, expect_digest):
if expect_digest:
break
else:
self.fail("Encountered digest mismatch when we shouldn't")
pytest.fail("Encountered digest mismatch when we shouldn't")
else:
if expect_digest:
self.fail("Didn't find digest mismatch")
pytest.fail("Didn't find digest mismatch")

def test_simple_repair_by_base(self):
self._simple_repair_test(repair_base=True)
@@ -55,7 +55,7 @@ def test_friendly_unrecognized_table_handling(self):

try:
session.execute(SimpleStatement("SELECT * FROM test_upgrades.foo", consistency_level=ConsistencyLevel.ALL))
self.fail("expected failure")
pytest.fail("expected failure")
except (ReadTimeout, OperationTimedOut):
logger.debug("Checking node2 for warning in log")
node2.watch_log_for(pattern, timeout=10)
@@ -64,7 +64,7 @@ def test_friendly_unrecognized_table_handling(self):
try:
session.execute(SimpleStatement("SELECT * FROM test_upgrades.foo", consistency_level=ConsistencyLevel.ALL,
fetch_size=None))
self.fail("expected failure")
pytest.fail("expected failure")
except (ReadTimeout, OperationTimedOut):
logger.debug("Checking node2 for warning in log")
pattern = r".*Got .* command for nonexistent table test_upgrades.foo.*"
@@ -75,7 +75,7 @@ def test_friendly_unrecognized_table_handling(self):
for i in range(20):
session.execute(SimpleStatement("SELECT * FROM test_upgrades.foo WHERE a = %d" % (i,),
consistency_level=ConsistencyLevel.ALL, fetch_size=None))
self.fail("expected failure")
pytest.fail("expected failure")
except (ReadTimeout, OperationTimedOut):
logger.debug("Checking node2 for warning in log")
pattern = r".*Got .* command for nonexistent table test_upgrades.foo.*"
@@ -36,7 +36,7 @@ def test_connect_to_ssl(self):
try: # hack around assertRaise's lack of msg parameter
# try to connect without ssl options
self.patient_cql_connection(node1)
self.fail('Should not be able to connect to SSL socket without SSL enabled client')
pytest.fail('Should not be able to connect to SSL socket without SSL enabled client')
except NoHostAvailable:
pass

@@ -78,7 +78,7 @@ def test_use_custom_port(self):
cluster.start()
try: # hack around assertRaise's lack of msg parameter
self.patient_cql_connection(node1)
self.fail('Should not be able to connect to non-default port')
pytest.fail('Should not be able to connect to non-default port')
except NoHostAvailable:
pass

@@ -347,7 +347,7 @@ def test_set_get_concurrent_view_builders(self):
assert 'concurrent_view_builders should be great than 0.' in e.stdout
assert 'Number of concurrent view builders should be greater than 0.', e.message
else:
self.fail("Expected error when setting and invalid value")
pytest.fail("Expected error when setting and invalid value")

@since('4.0')
def test_describecluster_more_information_three_datacenters(self):
@@ -365,7 +365,7 @@ def handle_scenario(scenario):
)
else:
# this should not happen
self.fail("Invalid scenario configuration. Scenario is: {}".format(scenario))
pytest.fail("Invalid scenario configuration. Scenario is: {}".format(scenario))

pf = PageFetcher(future).request_all()
assert pf.num_results_all() == scenario['expect_pgsizes']
@@ -3450,7 +3450,7 @@ def test_failure_threshold_deletions(self):
except Exception:
raise
else:
self.fail('Expected ReadFailure or ReadTimeout, depending on the cluster version')
pytest.fail('Expected ReadFailure or ReadTimeout, depending on the cluster version')

if self.cluster.version() < "3.0":
failure_msg = ("Scanned over.* tombstones in test_paging_size."
@@ -431,7 +431,7 @@ def read_failure_query():
except Exception:
raise
else:
self.fail('Expected ReadFailure')
pytest.fail('Expected ReadFailure')

read_failure_query()

@@ -463,7 +463,7 @@ def range_request_failure_query():
except Exception:
raise
else:
self.fail('Expected ReadFailure')
pytest.fail('Expected ReadFailure')

range_request_failure_query()

@@ -109,7 +109,7 @@ def check_trace_events(trace):
assert expected_per_range > 0
break
else:
self.fail("Didn't find matching trace event")
pytest.fail("Didn't find matching trace event")

query = SimpleStatement("SELECT * FROM ks.cf WHERE b='1';")
result = session.execute(query, trace=True)
@@ -283,7 +283,7 @@ def _assert_invalid_request(self, session, insert_cql, value):
def _execute_and_fail(self, operation, cql_string):
try:
operation()
self.fail("Expecting query {} to be invalid".format(cql_string))
pytest.fail("Expecting query {} to be invalid".format(cql_string))
except AssertionError as e:
raise e
except InvalidRequest:
@@ -567,7 +567,7 @@ def check_trace_events(trace, regex, expected_matches, on_failure):
on_failure(trace, regex, expected_matches, match_counts, event_source, min_matches, max_matches)

def halt_on_failure(trace, regex, expected_matches, match_counts, event_source, min_expected, max_expected):
self.fail("Expected to find between {min} and {max} trace events matching {pattern} from {source}, "
pytest.fail("Expected to find between {min} and {max} trace events matching {pattern} from {source}, "
"but actually found {actual}. (Full counts: {all})"
.format(min=min_expected, max=max_expected, pattern=regex, source=event_source,
actual=match_counts[event_source], all=match_counts))
@@ -385,7 +385,7 @@ def _base_expiration_overflow_policy_test(self, default_ttl, policy):
result = self.session1.execute_async(query + ";")
result.result()
if policy == 'REJECT':
self.fail("should throw InvalidRequest")
pytest.fail("should throw InvalidRequest")
if self.cluster.version() >= '3.0': # client warn only on 3.0+
if policy == 'CAP':
logger.debug("Warning is {}", result.warnings[0])
@@ -5083,7 +5083,7 @@ def test_invalid_string_literals(self):
# since the protocol requires strings to be valid UTF-8, the error response to this is a ProtocolError
try:
cursor.execute("insert into ks.invalid_string_literals (k, b) VALUES (0, '\xc2\x01')")
self.fail("Expected error")
pytest.fail("Expected error")
except ProtocolException as e:
assert "Cannot decode string as UTF8" in str(e)

@@ -40,7 +40,7 @@ def prepare(self):
def drop_compact_storage(self, session, assert_msg):
try:
session.execute("ALTER TABLE drop_compact_storage_test.test DROP COMPACT STORAGE")
self.fail("No exception has been thrown")
pytest.fail("No exception has been thrown")
except InvalidRequest as e:
assert assert_msg in str(e)

@@ -720,7 +720,7 @@ def _check_select_count(self, consistency_level=ConsistencyLevel.ALL):
actual_num_rows = result[0][0]
assert actual_num_rows == expected_num_rows, "SELECT COUNT(*) returned %s when expecting %s" % (actual_num_rows, expected_num_rows)
else:
self.fail("Count query did not return")
pytest.fail("Count query did not return")

class BootstrapMixin(object):
"""

0 comments on commit bca1834

Please sign in to comment.