jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.58k stars 4.85k forks source link

python ,unittest can't run . #2746

Open bluekyzhao opened 7 years ago

bluekyzhao commented 7 years ago

hi ,this code can't run in the jupyter-notebook.

but it runs well in other python's IDE

import unittest

def get_formatted_name(first, last):
    """Generate a neatly formatted full name."""
    full_name = first + ' ' + last
    return full_name.title()

class NamesTestCase(unittest.TestCase):
    def test_first_last_name(self):
        """Can it handle the name just like 'janis', 'joplin'?""" 
        formatted_name = get_formatted_name('janis', 'joplin') 
        self.assertEqual(formatted_name, 'Janis Joplin')
unittest.main()
E
======================================================================
ERROR: C:\Users\blueky\AppData\Roaming\jupyter\runtime\kernel-0b912e59-7f08-4853-ab4c-f6e9c86edc80 (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute 'C:\Users\blueky\AppData\Roaming\jupyter\runtime\kernel-0b912e59-7f08-4853-ab4c-f6e9c86edc80'

----------------------------------------------------------------------
Ran 1 test in 0.002s

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

SystemExit: True

c:\python36-32\lib\site-packages\IPython\core\interactiveshell.py:2870: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
JacksonIsaac commented 6 years ago

Running using the following line works for me: unittest.main(argv=['first-arg-is-ignored'], exit=False)

Reference: https://stackoverflow.com/a/38012249/1970068