Pytest instead of Nose for ex47


I have chosen to use Pytest instead of Nose for exercise 47.
Mainly beacuse it was for Pytest I found documentation that worked best for me.
I hope this code will be help for other.

#Pytest will be my choice for this exercise.

import pytest
from ex47 import game

def test_Room():
    room = game.Room('GoldRoom', 
    """This room has gold in it you can grab. There is a door to the north.""")
    assert == 'GoldRoom'
    assert room.paths == {}  

def test_room_paths():
    center = game.Room('Center','Test room in the center')
    north = game.Room('North','Test room in the north')
    south = game.Room('South','Test room in the south')
    center.add_paths({'north': north, 'south': south})

    assert center.go('south') == south
    assert center.go('north') == north

def test_map():
    start = game.Room("Start", "You can go west and fall down in a cave")
    west = game.Room("Trees", "There are only trees here, you can go east.")
    down = game.Room("Dungeon", "how did you get here? Get back up to the game!")

    start.add_paths({'west': west, 'down': down})
    west.add_paths({'east': start})
    down.add_paths({'up': start})

    assert start.go('west') == west
    assert start.go('west').go('east') == start
    assert start.go('down').go('up') == start

There is a thing called fixture in pytest.
I will see how it can be used in here.
Will report later with upgraded test.


Checkout mark.parametrize too. Super cool.

Hello @gpkesley.

Yes. I know. I used it when i did the book for Python2
Link my Github account
I learned that from a Youtube clip. Later I bought a book about Pytest (Python testing with Pytest).
Now I am at the same exercise in the book for Python3. But it was a while ago. So I think I have to read the book again.

Great book that, I also have a copy.

Hello @ulfen69 and @gpkesley

After struggling mightily myself with applying nosetests, I gave up and switched over to pytest following this thread. I would just like to thank you very much.

As a second point of interest, if one experiences problems with running pytest, using _test (singular form) as part of the test file name versus _tests (plural) did the trick for me

Can you be more explicit about which was correct? or

Hello @HS88.

I am glad you found it useful.
Search for pytest in this forum and you will find some more about using Pytest.
I wrote some of them to help myself understand it better. I know @gpkesley is very good at Pytest.

1 Like

Hi @zedshaw

Apologies for the ambiguity. The singular form was correct.

A free service run by Zed A. Shaw for