Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unit testing
#1
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?
Reply
#2
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"
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unit Testing Set Up and Use RockBlok 2 425 Jan-08-2024, 07:43 PM
Last Post: deanhystad
  Remove function and unit test ftg 5 3,535 Jan-07-2020, 03:10 PM
Last Post: ndc85430
  Odd Unit Test Behavior ichabod801 3 2,578 Jan-02-2020, 03:34 PM
Last Post: ichabod801
  Define unit of measure of a number doug2019 3 2,378 Oct-15-2019, 03:43 PM
Last Post: jefsummers
  Unit testing - AssertRaises kerzol81 3 4,563 Oct-07-2019, 10:35 AM
Last Post: buran
  unit testing a method that asks two user inputs() in console gebel 0 2,140 Apr-03-2019, 07:59 PM
Last Post: gebel
  unit test roll die saladgg 5 4,164 Nov-06-2018, 11:39 PM
Last Post: stullis
  Would you unit test __init__ method? kilthar 1 31,001 Oct-18-2017, 05:31 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020