Unable to run unittest's main function in ipython/jupyter notebook

unittest.main looks at sys.argv by default, which is what started IPython, hence the error about the kernel connection file not being a valid attribute. You can pass an explicit list to main to avoid looking up sys.argv.

In the notebook, you will also want to include exit=False to prevent unittest.main from trying to shutdown the kernel process:

unittest.main(argv=['first-arg-is-ignored'], exit=False)

You can pass further arguments in the argv list, e.g.

unittest.main(argv=['ignored', '-v'], exit=False)

We can try TestLoader to load test cases from TestCaseClass

and attach those testcases to TextTestRunner then run it.

import unittest
suite = unittest.TestLoader().loadTestsFromTestCase(Samples)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)