Python Forum

Full Version: Unit testing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a file called
calc.py 
and
test_calc.py
in my file called
test_calc.py
I have written:

import unittest
import calc

class TestCalc(unittest.TestCase):

    def test_add(self):
        result=calc.add(10,5)
        self.assertEqual(result,15)



When I try to run this file I get the following error in my interactive shell:

RESTART: C:/Users/sushi/AppData/Local/Programs/Python/Python36-32/test_calc.py 
Traceback (most recent call last):
  File "C:/Users/sushi/AppData/Local/Programs/Python/Python36-32/test_calc.py", line 1, in <module>
    import unittest
  File "C:\Users\sushi\AppData\Local\Programs\Python\Python36-32\lib\unittest\__init__.py", line 59, in <module>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File "C:\Users\sushi\AppData\Local\Programs\Python\Python36-32\lib\unittest\case.py", line 7, in <module>
    import pprint
  File "C:/Users/sushi/AppData/Local/Programs/Python/Python36-32\pprint.py", line 7, in <module>
    print(pprint.pformat(count))
AttributeError: module 'pprint' has no attribute 'pformat'
Why is this happening?
Did you write this file called pprint.py?
Quote:File "C:/Users/sushi/AppData/Local/Programs/Python/Python36-32\pprint.py", line 7, in <module>
By naming this file a name that is used in the standard library, your module is being used instead. More info here under "Naming your scripts and directories"