MCPcopy Create free account
hub / github.com/ipython/ipython / test_multiprocessing_run

Function test_multiprocessing_run

IPython/core/tests/test_run.py:562–588  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

560
561
562def test_multiprocessing_run():
563 """Set we can run mutiprocesgin without messing up up main namespace
564
565 Note that import `nose.tools as nt` mdify the value s
566 sys.module['__mp_main__'] so wee need to temporarily set it to None to test
567 the issue.
568 """
569 with TemporaryDirectory() as td:
570 mpm = sys.modules.get('__mp_main__')
571 assert mpm is not None
572 sys.modules['__mp_main__'] = None
573 try:
574 path = pjoin(td, 'test.py')
575 with open(path, 'w') as f:
576 f.write("import multiprocessing\nprint('hoy')")
577 with capture_output() as io:
578 _ip.run_line_magic('run', path)
579 _ip.run_cell("i_m_undefined")
580 out = io.stdout
581 nt.assert_in("hoy", out)
582 nt.assert_not_in("AttributeError", out)
583 nt.assert_in("NameError", out)
584 nt.assert_equal(out.count("---->"), 1)
585 except:
586 raise
587 finally:
588 sys.modules['__mp_main__'] = mpm
589
590@dec.knownfailureif(sys.platform == 'win32', "writes to io.stdout aren't captured on Windows")
591def test_script_tb():

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected