Skip to content

Commit 9dc6dbb

Browse files
sadpandajoeclaude
andcommitted
test: fix flaky MySQL test in test_update_v1_response
Add time.sleep(1) and normalize timestamps with .replace(microsecond=0) to handle MySQL's second-level datetime precision. This prevents test failures when the test executes within the same second. - MySQL DATETIME defaults to second precision, truncating microseconds - Pattern matches tests/integration_tests/dashboards/dao_tests.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent c2baba5 commit 9dc6dbb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/integration_tests/charts/commands_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
import time
1718
from unittest.mock import patch
1819

1920
import pytest
@@ -383,9 +384,15 @@ def test_update_v1_response(self, mock_sm_g, mock_c_g, mock_u_g):
383384
}
384385
command = UpdateChartCommand(model_id, json_obj)
385386
last_saved_before = db.session.query(Slice).get(pk).last_saved_at
387+
# Sleep to ensure timestamp differs at MySQL's second precision
388+
# MySQL DATETIME defaults to second-level precision, truncating microseconds
389+
time.sleep(1)
386390
command.run()
387391
chart = db.session.query(Slice).get(pk)
388-
assert chart.last_saved_at != last_saved_before
392+
# Normalize microseconds for database-agnostic comparison
393+
assert chart.last_saved_at.replace(microsecond=0) != last_saved_before.replace(
394+
microsecond=0
395+
)
389396
assert chart.last_saved_by == user
390397

391398
@patch("superset.utils.core.g")

0 commit comments

Comments
 (0)