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 Writing and Running Doctests

My test is failing and it's unclear why/how.

Here's the code in question:

def get_moves(player):
    """Based on the tuple of the player's postition, return the list
    of accetable moves

    >>> GAME_DIMENSIONS = (2,2)                                                                           
    >>> get_moves((0,2))                                                                                  
    ['RIGHT', 'UP', 'DOWN']  

    """
    x, y = player
    moves = ['LEFT', 'RIGHT', 'UP', 'DOWN']
    if x == 0:
        moves.remove('LEFT')
    if x == GAME_DIMENSIONS[0] - 1:
        moves.remove('RIGHT')
    if y == 0:
        moves.remove('UP')
    if y == GAME_DIMENSIONS[1] - 1:
        moves.remove('DOWN')
    return moves

and the test failing in the console shows me this:

treehouse:~/workspace/dungeon$ python -m doctest dd_game.py


File "/home/treehouse/workspace/dungeon/dd_game.py", line 65, in dd_game.get_moves
Failed example:
get_moves((0,2))
Expected:
['RIGHT', 'UP', 'DOWN']
Got:
['RIGHT', 'UP', 'DOWN']


1 items had failures:
1 of 2 in dd_game.get_moves
Test Failed 1 failures.

This... this doesn't make sense... THEY'RE THE SAME!

Any help would be greatly appreciated! :)

Josh Keenan
Josh Keenan
20,315 Points

Can you link to your workspace please, very stumped on this just from a read through.

Josh Keenan
Josh Keenan
20,315 Points

Also I have to say, your name is truly exceptional.

Richard Beades
Richard Beades
2,338 Points

I had this issue too, its the copy and paste from the repl, it adds in a load of extra white space, if you remove all the white space then it will work okay.

2 Answers

Welp... I'm baffled. I went to get a link to my workspace, made no edits at all, decided to test it again, aaaaaand it passed.

I have no idea what is going on. Glitch in the matrix?

I'm so sorry. Thank you for your time :sweat_smile:

Josh Keenan
Josh Keenan
20,315 Points

Don't be my dude, that is weird as hell and sometimes you get stuff like that.

Benjamin Gooch
Benjamin Gooch
20,367 Points

So i got the same when I first ran my test. Your issue may be different than mine, but in my case, I had white space following the ['RIGHT', 'UP', 'DOWN'] in my code. It comes from copy and pasting.

Click on the beginning of the line below this line and left arrow until you hit the last character of the line containing the ['RIGHT', 'UP', 'DOWN']. I bet there's some extra spaces hiding there!

Benjamin Gooch
Benjamin Gooch
20,367 Points

As a matter of fact, I just checked the code snippet you posted here and I found 2 spaces following ['RIGHT', 'UP', 'DOWN'].

Get rid of that business and it should pass just fine.