0

I've been trying to integrate jupyter as a testing playground to an existing python framework. The framework requires a set of python statements to execute in order to initialise and connect to database before actual testing can begin.

So, it there a way to pass a set of default execution statements whenever a new Notebook is spawned in browser?

  • This has to be completely automatic.
  • User doesn't need to know that there's this file that you need to load.
  • It shouldn't clutter their user directory.
  • Complete code should be displayed in the first cell, and executed whenever new browser window starts, or kernel is reloaded.

Is there a way to do this?

Edit: Found the proper solution.

ipython -i <path_to_python_file>

This could be integrated in the framework to be seamless and will not require user to manually maintain anything in their user directory.

Himanshu Mishra
  • 310
  • 3
  • 13
  • Actually launching a notebook as part of a test for something else doesn't seem like a great idea. You should consider mocking it. Look at the `mock` module. – cs95 Aug 18 '18 at 09:29
  • Add startup scripts in `~/.ipython/profile_default/startup`. There is a `README` file there to teach you. – Sraw Aug 18 '18 at 09:36
  • @ivan_pozdeev This is not really a duplicate. Other answers only provide how to manually load from a file or add to profile. I want something like running a python script and then Embedding I-Python console. But in jupyter. – Himanshu Mishra Aug 20 '18 at 18:52
  • @coldspeed please see above comment – Himanshu Mishra Aug 20 '18 at 18:53

0 Answers0