Skip to content

Commit a4864e8

Browse files
authored
fix: patch rather than sleep for time sensitive pytest (#1344)
Attempt to fix test_read_remote_setting that fails sporadically.
1 parent 2dcbc2e commit a4864e8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/unit/test_application_settings.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import time
15+
import datetime
1616
from unittest.mock import Mock, patch
1717

1818
import pytest
@@ -124,15 +124,27 @@ def test_read_remote_setting(eda_caplog):
124124
},
125125
]
126126

127-
with patch("aap_eda.analytics.utils.requests.get") as mock_get:
127+
now = datetime.datetime(2025, 1, 1, 0, 0)
128+
now_effect = [
129+
now,
130+
now + datetime.timedelta(milliseconds=100),
131+
now + datetime.timedelta(milliseconds=200),
132+
now + datetime.timedelta(milliseconds=300),
133+
now + datetime.timedelta(milliseconds=1400),
134+
now + datetime.timedelta(milliseconds=1500),
135+
]
136+
137+
with (
138+
patch("django.utils.timezone.now", side_effect=now_effect),
139+
patch("aap_eda.analytics.utils.requests.get") as mock_get,
140+
):
128141
mock_get.return_value = mock_resp
129142
assert application_settings.AUTOMATION_ANALYTICS_GATHER_INTERVAL == 500
130143
assert application_settings.REDHAT_USERNAME == "foo"
131144
# repeat within interval
132145
assert application_settings.AUTOMATION_ANALYTICS_GATHER_INTERVAL == 500
133146
assert application_settings.REDHAT_USERNAME == "foo"
134147

135-
time.sleep(1)
136148
# repeat after interval
137149
assert (
138150
application_settings.AUTOMATION_ANALYTICS_GATHER_INTERVAL == 1000

0 commit comments

Comments
 (0)