Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python ,unittest can't run . #2746

Open
bluekyzhao opened this issue Aug 11, 2017 · 1 comment
Open

python ,unittest can't run . #2746

bluekyzhao opened this issue Aug 11, 2017 · 1 comment

Comments

@bluekyzhao
Copy link

bluekyzhao commented Aug 11, 2017

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
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants