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 First Steps With Testing Simple Unit Test

Oziel Perez
Oziel Perez
61,321 Points

AttributeError on Python Testing Challenge

I can't seem to figure out why, on the second part of the challenge, I keep getting this error:

AttributeError: 'module' object has no attribute '1'

What does that even mean? Aren't attributes not supposed to start with a number to begin with? Anyways, I tried running the challenge on a workspace and the test passed successfully. I'm just thinking about filing a bug report because I don't think this is supposed to happen, unless someone else knows something about this that I don't

Here's the full code:

tests.py
import unittest

class SimpleTestCase(unittest.TestCase):
  def test_simple(self):
    assert 10 - 10 == 0

if __name__ == '__main__':
  unittest.main()

3 Answers

Oziel Perez
Oziel Perez
61,321 Points

Oh woooow hahaha well I managed to figure it out after 2 minutes of posting this!! Ok so the code above works perfect. All that needs to be done is to remove the whole if name == 'main' block of code. I had placed that there to see if it would help but turns out that made it worse. So in the end the error was probably because I had forgotten to start my method with the word "test_", but the challenge didn't succeed because that "if" block was still causing errors. I'll leave this incident posted for everyone to see in case if they run into something like this.

I need help with the task 2 question: "Create a TestCase named SimpleTestCase with a simple test that asserts that 10 - 10 is 0. Remember, unittest test names have to start with test_." This is for the "Simple Unit Test". Can you help me by showing the correct code?

Dana Kennedy
Dana Kennedy
6,711 Points

This worked as the final code.

import unittest

class SimpleTestCase(unittest.TestCase): def test_10_minus_10(self): assert 10 - 10 == 0

I tried it and it still doesn't work....its my fault somehow!

import unittest

class SimpleTestCase(unittest.TestCase): def test _10_minus_10(self): assert 10 - 10 === 0

I had to copy and paste the above... really hate that because I wanted to learn it by the sweat of my brow but finally passed. Its about time!