MCPcopy
hub / github.com/marimo-team/marimo / run_pytest

Function run_pytest

marimo/_runtime/pytest.py:346–414  ·  view source on GitHub ↗
(
    defs: set[str] | None = None,
    lcls: dict[str, Any] | None = None,
    notebook_path: Path | str | None = None,
)

Source from the content-addressed store, hash-verified

344
345
346def 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 )

Callers 2

test_batched_cellsFunction · 0.90
test_isolation_cellsFunction · 0.90

Calls 7

capture_stdoutFunction · 0.90
ReplaceStubPluginClass · 0.85
requireMethod · 0.80
_get_nameFunction · 0.70
copyMethod · 0.65
updateMethod · 0.65
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…