MCPcopy
hub / github.com/streamlit/streamlit / assert_snapshot

Function assert_snapshot

e2e_playwright/conftest.py:1351–1578  ·  view source on GitHub ↗

Fixture that compares a screenshot with screenshot from a past run.

(
    request: pytest.FixtureRequest,
    output_folder: Path,
    pytestconfig: Any,
)

Source from the content-addressed store, hash-verified

1349
1350@pytest.fixture
1351def assert_snapshot(
1352 request: pytest.FixtureRequest,
1353 output_folder: Path,
1354 pytestconfig: Any,
1355) -> Generator[ImageCompareFunction, None, None]:
1356 """Fixture that compares a screenshot with screenshot from a past run."""
1357
1358 # Check if reruns are enabled for this test run
1359 flaky_marker = request.node.get_closest_marker("flaky")
1360 if flaky_marker and "reruns" in flaky_marker.kwargs:
1361 configured_reruns = flaky_marker.kwargs["reruns"]
1362 else:
1363 configured_reruns = pytestconfig.getoption("reruns", 0)
1364 # Get the current execution count:
1365 execution_count = getattr(request.node, "execution_count", 1)
1366 # True if this is the last rerun (or the only test run)
1367 is_last_rerun = execution_count - 1 == configured_reruns
1368
1369 root_path = get_git_root()
1370
1371 platform = str(sys.platform)
1372 module_name = request.module.__name__.split(".")[-1]
1373 test_function_name = request.node.originalname
1374
1375 snapshot_dir: Path = (
1376 root_path / "e2e_playwright" / "__snapshots__" / platform / module_name
1377 )
1378
1379 module_snapshot_failures_dir: Path = (
1380 output_folder / "snapshot-tests-failures" / platform / module_name
1381 )
1382 module_snapshot_updates_dir: Path = (
1383 output_folder / "snapshot-updates" / platform / module_name
1384 )
1385
1386 snapshot_file_suffix = ""
1387 # Extract the parameter ids if they exist
1388 match = re.search(r"\[(.*?)\]", request.node.name)
1389 if match:
1390 snapshot_file_suffix = f"[{match.group(1)}]"
1391
1392 snapshot_default_file_name: str = test_function_name + snapshot_file_suffix
1393
1394 test_failure_messages: list[str] = []
1395
1396 def compare(
1397 element: ElementHandle | Locator | Page,
1398 *,
1399 image_threshold: float = 0.002,
1400 pixel_threshold: float = 0.05,
1401 name: str | None = None,
1402 fail_fast: bool = False,
1403 file_type: Literal["png", "jpg"] = "png",
1404 style: str | None = None,
1405 show_app_header: bool | None = None,
1406 ) -> None:
1407 """Compare a screenshot with screenshot from a past run.
1408

Calls 2

get_git_rootFunction · 0.90
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…