Hydrogen: Running unit tests in Python kernel

Created on 29 May 2017  路  4Comments  路  Source: nteract/hydrogen

Hi,

Is it possible to run Python's unittest.main() in Hydrogen? I haven't found any info, so I don't know if it is a bug or a limitation.

The test runs in the IPython shell.

ERROR: /run/user/1000/jupyter/kernel-9871a573-6183-41d6-b478-ee33edba7173 (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute '/run/user/1000/jupyter/kernel-9871a573-6183-41d6-b478-ee33edba7173'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)
An exception has occurred, use %tb to see the full traceback.

SystemExit: True
/usr/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

Most helpful comment

This version of the .main call:

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

works fine for me. (Source.)

All 4 comments

Do the tests work inside the jupyter notebook?

Well, it doesn't work in Jupyter when using

if __name__ == '__main__':
    unittest.main()

but works with something like

test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(TestStringMethods))
runner=unittest.TextTestRunner()
runner.run(test_suite)

So, not a Hydrogen problem, I believe.

This version of the .main call:

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

works fine for me. (Source.)

Closing since a solution seems to have been found! :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wadethestealth picture wadethestealth  路  3Comments

neurotronix picture neurotronix  路  4Comments

gepcel picture gepcel  路  3Comments

danbri picture danbri  路  4Comments

Mungoid picture Mungoid  路  4Comments