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

Function test_extension

tests/test_magic.py:976–1005  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

974
975
976def test_extension():
977 # Debugging information for failures of this test
978 assert "daft_extension" not in sys.modules
979 daft_path = os.path.join(os.path.dirname(__file__), "fake_ext_dir")
980 if daft_path in sys.path:
981 # it is likely pytest added this path
982 # when scanning for tests
983 sys.path.remove(daft_path)
984 print("sys.path:")
985 for p in sys.path:
986 print(" ", p)
987 print("CWD", os.getcwd())
988
989 with pytest.raises(ModuleNotFoundError):
990 import daft_extension
991
992 with pytest.raises(ModuleNotFoundError):
993 _ip.run_line_magic("load_ext", "daft_extension")
994 sys.path.insert(0, daft_path)
995 import daft_extension
996
997 try:
998 _ip.user_ns.pop("arq", None)
999 invalidate_caches() # Clear import caches
1000 _ip.run_line_magic("load_ext", "daft_extension")
1001 assert _ip.user_ns["arq"] == 185
1002 _ip.run_line_magic("unload_ext", "daft_extension")
1003 assert "arq" not in _ip.user_ns
1004 finally:
1005 sys.path.remove(daft_path)
1006
1007
1008def test_notebook_export_json():

Callers

nothing calls this directly

Calls 3

run_line_magicMethod · 0.80
popMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…