Skip to content

Commit d42123b

Browse files
authored
chore: only enable/disable a single policy in test_enable_alert_policies (#157)
This PR attempts to resolve #150 by only enabling/ disabling a single alert policy, rather than enabling/ disabling all alert polices in the specified project in order to reduce the output that we need to parse for the expected result. From the build log in #150 :`'"snippets-test-ugrikrch..."projects/python-docs-samples-tests-py37'`, the `...` indicates that information is being truncated which would cause flaky results. Fixes #150 🦕
1 parent 24c6303 commit d42123b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

monitoring/snippets/v3/alerts-client/snippets_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def pochan():
125125
def test_list_alert_policies(capsys, pochan):
126126
snippets.list_alert_policies(pochan.project_name)
127127
out, _ = capsys.readouterr()
128-
assert pochan.alert_policy.display_name in out
128+
# Only check up to the first 20 characters of the display name
129+
# as long strings printed to the console are truncated.
130+
assert pochan.alert_policy.display_name[0:20] in out
129131

130132

131133
@pytest.mark.flaky(rerun_filter=delay_on_aborted, max_runs=5)
@@ -136,15 +138,15 @@ def test_enable_alert_policies(capsys, pochan):
136138
# Having multiple projects will void these `sleep()` calls.
137139
# See also #3310
138140
time.sleep(2)
139-
snippets.enable_alert_policies(pochan.project_name, True)
141+
snippets.enable_alert_policies(pochan.project_name, True, "name='{}'".format(pochan.alert_policy.name))
140142
out, _ = capsys.readouterr()
141143
assert (
142144
"Enabled {0}".format(pochan.project_name) in out
143145
or "{} is already enabled".format(pochan.alert_policy.name) in out
144146
)
145147

146148
time.sleep(2)
147-
snippets.enable_alert_policies(pochan.project_name, False)
149+
snippets.enable_alert_policies(pochan.project_name, False, "name='{}'".format(pochan.alert_policy.name))
148150
out, _ = capsys.readouterr()
149151
assert (
150152
"Disabled {}".format(pochan.project_name) in out

0 commit comments

Comments
 (0)