Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Testing Be Assertive Membership and Other Assertions

James N
James N
17,864 Points

[RESOLVED] Was this me? ImportError: Failed to import test module: tests

for some reason, i seem to be getting an error that LOOKS like it was treehouse. (it probably isn't.)

the error:

error.txt
treehouse:~/workspace/dice$ python -m unittest tests.py                                                                                                                                  
E                                                                                                                                                                                        
======================================================================                                                                                                                   
ERROR: tests (unittest.loader._FailedTest)                                                                                                                                               
----------------------------------------------------------------------                                                                                                                   
ImportError: Failed to import test module: tests                                                                                                                                         
Traceback (most recent call last):                                                                                                                                                       
  File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName                                                                                
    module = __import__(module_name)                                                                                                                                                     
ImportError: No module named 'tests'                                                                                                                                                     


----------------------------------------------------------------------                                                                                                                   
Ran 1 test in 0.000s                                                                                                                                                                     

FAILED (errors=1)                                                                                                                                                                        
treehouse:~/workspace/dice$

the code:

test.py
import unittest
import dice

class DieTest(unittest.TestCase):
    def setUp(self):
        self.d6 = dice.Die(6)
        self.d8 = dice.Die(8)

    def test_creation(self):
        self.assertEqual(self.d6.sides, 6)
        self.assertIn(self.d6.value, range(1, 7))
Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi,

maybe it's only an error here in the answer. Are you sure that your file is named "tests.py"?

1 Answer

James N
James N
17,864 Points

nvm... it was me. i typed TESTS.py, instead of TEST.py. facepalm

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Sorry I was testing with you answer opened in another page and see now! Glad that you resolve your issue!

I've made the same mistake and found the answer here. Thank you!