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 trialKathryn Klarich
4,622 Points"MoveTests has no attribute 'rock'"
Thanks in advance for your help! I'm trying to follow the video and I believe my script is identical to Kenneth's, however, when i run the script i get the errors:
Traceback (most recent call last):
File "tests.py", line 21, in test_equal
self.assertEqual(self.rock, moves.Rock())
AttributeError: 'MoveTests' object has no attribute 'rock'
Traceback (most recent call last):
File "tests.py", line 21, in test_equal
self.assertEqual(self.rock, moves.Rock())
AttributeError: 'MoveTests' object has no attribute 'rock'
see below for my code:
import unittest
import moves
class MoveTests(unittest.TestCase): def setUp(self): self.rock = moves.Rock() self.paper = moves.Paper() self.scissors = moves.Scissors()
class MoveTests(unittest.TestCase): def test_five_plus_five(self): assert 5 + 5 == 10
def test_one_plus_one(self):
assert not 1 + 1 == 3
def test_equal(self):
self.assertEqual(self.rock, moves.Rock())
def test_not_equal(self):
self.assertNotEqual(self.rock, self.paper)
if name == 'main': unittest.main()
1 Answer
jacinator
11,936 PointsYour only issue is that you are creatign MoveTests
twice. It won't call the setUp
from the first class from the second class. You'll simply need to combine the two classes.
import unittest
import moves
class MoveTests(unittest.TestCase):
def setUp(self):
self.rock = moves.Rock()
self.paper = moves.Paper()
self.scissors = moves.Scissors()
def test_five_plus_five(self):
assert 5 + 5 == 10
def test_one_plus_one(self):
assert not 1 + 1 == 3
def test_equal(self):
self.assertEqual(self.rock, moves.Rock())
def test_not_equal(self):
self.assertNotEqual(self.rock, self.paper)
if name == 'main':
unittest.main()
Kathryn Klarich
4,622 PointsKathryn Klarich
4,622 PointsThat worked, thanks!