Skip to content

Take the initial viz test screenshots from the newest image - #4095

Merged
EwoutH merged 1 commit into
mesa:mainfrom
AshNicolus:fix/viz-test-initial-screenshot
Nov 16, 2026
Merged

EwoutH merged 1 commit into
mesa:mainfrom
AshNicolus:fix/viz-test-initial-screenshot

Conversation

@AshNicolus

Copy link
Copy Markdown
Contributor

Pre-PR Checklist

  • This PR is a bug fix, not a new feature or enhancement.

Summary

Fixes the flaky Playwright viz tests by taking the two initial screenshots from the newest image, like the later screenshots already do.

Bug / Issue

Fixes #4094

After display(), the page briefly holds the old and the new <img>. The initial screenshots use the bare locator("img"), so if they run in that window, Playwright's strict mode fails with "resolved to 2 elements". This failed CI on #3953 and #4064 this week.

sequenceDiagram
    participant T as test
    participant P as page
    T->>P: display(graph_viz)
    Note over P: old img + new img (briefly)
    T->>P: locator("img").screenshot()
    P-->>T: strict mode violation (2 elements)
    Note over T: with .last: always the new img
Loading

Implementation

.last on the two initial screenshots in run_model_test. #3039 and #3670 made the same change for the screenshots after the model steps, so all four now pick the image the same way.

Testing

  • Counted images right after display(graph_viz): 2 on the first check, then 1, and .last was always the new image (6 of 6 runs).
  • Taking the screenshot right after display() reproduces the CI error every time on main. With .last, all 9 viz tests pass in that setup (3 of 3 runs).
  • pytest tests/examples/test_examples_viz.py: 9 passed. Pre-commit passes.

@github-actions github-actions Bot added the testing Release notes label label Nov 14, 2026
@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -0.9% [-3.2%, +1.4%] 🔵 -0.2% [-1.6%, +1.1%]
BoltzmannWealth large 🔵 -0.7% [-1.5%, +0.4%] 🔵 +1.4% [-0.1%, +3.0%]
Schelling small 🔵 -1.8% [-3.2%, -0.5%] 🔵 -0.1% [-1.4%, +1.1%]
Schelling large 🔵 -2.4% [-3.6%, -1.0%] 🔵 -4.0% [-7.0%, -1.0%]
WolfSheep small 🔵 -2.8% [-4.5%, -1.0%] 🔵 -0.7% [-5.2%, +4.4%]
WolfSheep large 🔵 +0.4% [-1.5%, +2.6%] 🔵 -0.3% [-2.2%, +1.7%]
SugarscapeG1mt small 🔵 -1.5% [-3.1%, +0.1%] 🔵 -1.3% [-3.4%, +0.7%]
SugarscapeG1mt large 🔴 +8.3% [+5.1%, +10.9%] 🔵 -0.8% [-2.6%, +1.1%]
BoidFlockers small 🔵 +1.4% [+0.1%, +2.8%] 🔵 -1.1% [-2.8%, +0.7%]
BoidFlockers large 🔵 +0.1% [-1.8%, +2.0%] 🔵 +0.3% [-1.2%, +2.3%]
MultiLevelAllianceModel small 🔵 +5.5% [+3.0%, +8.0%] 🔵 +0.3% [-1.6%, +2.3%]
MultiLevelAllianceModel large 🔵 +4.2% [+0.9%, +7.8%] 🔵 -1.4% [-4.4%, +1.1%]

@EwoutH EwoutH left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unpredictable test error was quite irritating. Thanks!

@EwoutH
EwoutH merged commit 667c62b into mesa:main Nov 16, 2026
17 checks passed
EwoutH pushed a commit that referenced this pull request Nov 22, 2026
Fixes the flaky Playwright viz tests by taking the two initial screenshots from the newest image, like the later screenshots already do.

(cherry picked from commit 667c62b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky Playwright viz tests: initial screenshots hit a strict mode violation

2 participants