Skip to content

Commit aa5c707

Browse files
committed
tests: avoid side effects in assertions
1 parent 287b49a commit aa5c707

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

tests/unit/test_cluster.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,8 @@ def test_initial_pool_clean_close_forces_host_recovery(self):
24642464
'cassandra.cluster.HostConnection',
24652465
side_effect=startup_error):
24662466
session.add_or_renew_pool(host, is_host_addition=False)
2467-
assert not tasks.pop()()
2467+
task_result = tasks.pop()()
2468+
assert not task_result
24682469

24692470
session.cluster.signal_connection_failure.assert_called_once_with(
24702471
host,
@@ -2516,7 +2517,8 @@ def _on_down_locked(
25162517
'cassandra.cluster.HostConnection',
25172518
side_effect=startup_error):
25182519
session.add_or_renew_pool(host, is_host_addition=False)
2519-
assert not tasks.pop()()
2520+
task_result = tasks.pop()()
2521+
assert not task_result
25202522

25212523
assert session.cluster.down_calls == [
25222524
(host, False, True, True),
@@ -2569,7 +2571,8 @@ def _on_down_locked(
25692571
'cassandra.cluster.HostConnection',
25702572
side_effect=startup_error):
25712573
session.add_or_renew_pool(host, is_host_addition=False)
2572-
assert not tasks.pop()()
2574+
task_result = tasks.pop()()
2575+
assert not task_result
25732576

25742577
assert calls == [
25752578
("public", True),
@@ -2615,7 +2618,8 @@ def on_down(
26152618
'cassandra.cluster.HostConnection',
26162619
side_effect=startup_error):
26172620
session.add_or_renew_pool(host, is_host_addition=False)
2618-
assert not tasks.pop()()
2621+
task_result = tasks.pop()()
2622+
assert not task_result
26192623

26202624
assert session.cluster.down_calls == [
26212625
(host, False, True),
@@ -2638,7 +2642,8 @@ def test_stale_startup_close_does_not_mark_host_down(self):
26382642
side_effect=startup_error):
26392643
session.add_or_renew_pool(host, is_host_addition=False)
26402644
session.remove_pool(host)
2641-
assert not tasks.pop()()
2645+
task_result = tasks.pop()()
2646+
assert not task_result
26422647

26432648
session.cluster.signal_connection_failure.assert_not_called()
26442649

@@ -2652,7 +2657,8 @@ def test_invalid_initial_keyspace_does_not_mark_host_down(self):
26522657
'cassandra.cluster.HostConnection',
26532658
side_effect=keyspace_error):
26542659
session.add_or_renew_pool(host, is_host_addition=False)
2655-
assert not tasks.pop()()
2660+
task_result = tasks.pop()()
2661+
assert not task_result
26562662

26572663
session.cluster.signal_connection_failure.assert_not_called()
26582664

@@ -2671,7 +2677,8 @@ def test_invalid_changed_keyspace_does_not_mark_host_down(self):
26712677
'cassandra.cluster.HostConnection',
26722678
return_value=new_pool):
26732679
session.add_or_renew_pool(host, is_host_addition=False)
2674-
assert not tasks.pop()()
2680+
task_result = tasks.pop()()
2681+
assert not task_result
26752682

26762683
session.cluster.on_down.assert_not_called()
26772684
new_pool.shutdown.assert_called_once_with()
@@ -2743,7 +2750,8 @@ def test_pool_finishing_after_shutdown_is_closed_not_published(self):
27432750
return_value=new_pool):
27442751
session.add_or_renew_pool(host, is_host_addition=False)
27452752
session.shutdown()
2746-
assert tasks.pop()() is _STALE_POOL_ATTEMPT
2753+
task_result = tasks.pop()()
2754+
assert task_result is _STALE_POOL_ATTEMPT
27472755

27482756
assert host not in session._pools
27492757
new_pool.shutdown.assert_called_once_with()
@@ -2760,7 +2768,8 @@ def test_pool_finishing_after_host_down_is_closed_not_published(self):
27602768
session.add_or_renew_pool(host, is_host_addition=False)
27612769
host.set_down()
27622770
session.on_down(host)
2763-
assert tasks.pop()() is _STALE_POOL_ATTEMPT
2771+
task_result = tasks.pop()()
2772+
assert task_result is _STALE_POOL_ATTEMPT
27642773

27652774
assert host not in session._pools
27662775
new_pool.shutdown.assert_called_once_with()
@@ -2779,7 +2788,8 @@ def test_unregistered_session_cannot_publish_pool_after_host_down(self):
27792788
# concurrent DOWN cannot invalidate this attempt through
27802789
# Session.on_down. Host state must fence publication itself.
27812790
host.set_down()
2782-
assert tasks.pop()() is _STALE_POOL_ATTEMPT
2791+
task_result = tasks.pop()()
2792+
assert task_result is _STALE_POOL_ATTEMPT
27832793

27842794
assert host not in session._pools
27852795
new_pool.shutdown.assert_called_once_with()
@@ -2798,8 +2808,10 @@ def test_concurrent_renewals_publish_only_one_pool(self):
27982808
side_effect=[first_pool, second_pool]):
27992809
session.add_or_renew_pool(host, is_host_addition=False)
28002810
session.add_or_renew_pool(host, is_host_addition=False)
2801-
assert tasks.pop(0)() is True
2802-
assert tasks.pop(0)() is _STALE_POOL_ATTEMPT
2811+
task_result = tasks.pop(0)()
2812+
assert task_result is True
2813+
task_result = tasks.pop(0)()
2814+
assert task_result is _STALE_POOL_ATTEMPT
28032815

28042816
assert session._pools[host] is first_pool
28052817
old_pool.shutdown.assert_called_once_with()

0 commit comments

Comments
 (0)