MCPcopy Index your code
hub / github.com/ipython/ipython / test_multiprocessing_run

Function test_multiprocessing_run

tests/test_run.py:639–664  ·  view source on GitHub ↗

Set we can run mutiprocesgin without messing up up main namespace Note that import `nose.tools as nt` modify the values sys.module['__mp_main__'] so we need to temporarily set it to None to test the issue.

()

Source from the content-addressed store, hash-verified

637
638
639def test_multiprocessing_run():
640 """Set we can run mutiprocesgin without messing up up main namespace
641
642 Note that import `nose.tools as nt` modify the values
643 sys.module['__mp_main__'] so we need to temporarily set it to None to test
644 the issue.
645 """
646 with TemporaryDirectory() as td:
647 mpm = sys.modules.get("__mp_main__")
648 sys.modules["__mp_main__"] = None
649 try:
650 path = pjoin(td, "test.py")
651 with open(path, "w", encoding="utf-8") as f:
652 f.write("import multiprocessing\nprint('hoy')")
653 with capture_output() as io:
654 _ip.run_line_magic("run", path)
655 _ip.run_cell("i_m_undefined")
656 out = io.stdout
657 assert "hoy" in out
658 assert "AttributeError" not in out
659 assert "NameError" in out
660 assert out.count("---->") == 1
661 except:
662 raise
663 finally:
664 sys.modules["__mp_main__"] = mpm
665
666
667def test_script_tb():

Callers

nothing calls this directly

Calls 5

capture_outputClass · 0.85
getMethod · 0.80
run_line_magicMethod · 0.80
writeMethod · 0.45
run_cellMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…