(
defs: set[str] | None = None,
lcls: dict[str, Any] | None = None,
notebook_path: Path | str | None = None,
)
| 344 | |
| 345 | |
| 346 | def run_pytest( |
| 347 | defs: set[str] | None = None, |
| 348 | lcls: dict[str, Any] | None = None, |
| 349 | notebook_path: Path | str | None = None, |
| 350 | ) -> MarimoPytestResult: |
| 351 | # Note, there does seem to be a bit of a race condition if the file hasn't |
| 352 | # saved yet... |
| 353 | # But I think this may only be noticeable with rapidly adding, renaming, and |
| 354 | # running tests. |
| 355 | DependencyManager.pytest.require( |
| 356 | "pytest is required for reactive " |
| 357 | "testing. Please report to github if you would like a different testing " |
| 358 | "suite supported." |
| 359 | ) |
| 360 | |
| 361 | import pytest # type: ignore |
| 362 | |
| 363 | if not notebook_path: |
| 364 | # Translate name to python module |
| 365 | notebook_path = _get_name() |
| 366 | notebook_path = str(notebook_path) |
| 367 | |
| 368 | # Hold on to modules since we want to refresh them in order to enable |
| 369 | # repeated calls. |
| 370 | module_snapshot = dict(sys.modules) |
| 371 | # Paths may be altered by pytest. To prevent accumulation- we refresh the |
| 372 | # path to the original state. |
| 373 | # NB. refer to pytester the most native solution (not used here, since it |
| 374 | # seems reasonable to just hook in this way). |
| 375 | path_snapshot = sys.path.copy() |
| 376 | |
| 377 | # qq and disable warnings suppress a fair bit of filler noise. |
| 378 | # color=yes seems to work nicely, but code-highlight is a bit much. |
| 379 | # Ideally, --import-mode=importlib would be a great flag- however the |
| 380 | # method is too brittle to handle absolute paths. As such, we default to |
| 381 | # the normal behavior (in which pytest alters the system path). |
| 382 | plugin = ReplaceStubPlugin(defs, lcls) |
| 383 | try: |
| 384 | # pytest in wasm doesn't seem to set environment variables correctly. |
| 385 | # This work around is to prevent collision with non-wasm testing. |
| 386 | os.environ["MARIMO_PYTEST_WASM"] = "1" |
| 387 | with capture_stdout() as stdout: |
| 388 | pytest.main( |
| 389 | [ |
| 390 | "-qq", |
| 391 | "--disable-warnings", |
| 392 | "--color=yes", |
| 393 | "--code-highlight=no", |
| 394 | "-p", |
| 395 | "no:codecov", # Disable codecov plugin to avoid duplicate reports |
| 396 | "-p", |
| 397 | "no:sugar", # Disable sugar plugin to avoid duplicate reports |
| 398 | "-p", |
| 399 | "no:cacheprovider", # Skip .pytest_cache I/O |
| 400 | notebook_path, |
| 401 | ], |
| 402 | plugins=[plugin], |
| 403 | ) |
no test coverage detected
searching dependent graphs…