Pytests and nosetests ran 0 tests

I actually got nosetests working before I reset my laptop. However, after resetting my laptop this afternoon, and after I reinstalled everything, I suddenly got ran 0 tests problem. So I decided to switch to pytest because I saw a lot of people recommended pytest in this forum. After installing pytest, I still got collected 0 items problem.
(I’m 100% sure syntax and folders are correct, they worked for nosetests before but not now.)

Below are my pytest code:

import pytest
from ex47.game import Room


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


def test_room_paths():
    center = Room("Center", "Test room in the center.")
    north = Room("North", "Test room in the north.")
    south = Room("South", "Test room in the south.")

    center.add_paths({'north': north, 'south': south})
    assert center.go('north') == north
    assert center.go('south') == south


def test_map():
    start = Room("Start", "You can go west and down a hole.")
    west = Room("Trees", "There are trees here, you can go esat.")
    down = Room("Dungeon", "It's dark down here, you can go up.")

    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

Below is the terminal output:

(lpthw) PS C:\Users\shane\lpthw\ex47\skeleton> pytest    
================================= test session starts ============================ 
platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\shane\lpthw\ex47\skeleton
collected 0 items                                                                                                                                             

================================= no tests ran in 0.03s ========================== 

PS: I’m working on Visual Studio Code and the interpreter path is set to the virtual environment (.venvs/lpthw/Scripts/python). I installed both nose and pytest in virtual environment so I have to start from here otherwise vscode throws “pylint unable to import blahblah” problem.

Not sure which part went wrong, need some help!
Thanks in advance!

Hello @CodeX

Do you have an empty  __init__.py in your test folder? 
Perhaps you need one in the ex47 folder too.

If it’s a clean install, have you install the project package:

pip install -e <path/url to where setup.py exists> 

I overlooked this a few times when moving packages around in my machine. The -e is to endure it’s —editable

Also make sure the names of your test files match pytests search rules, they’re slightly different from nose. (Pytest doesn’t accept files with tests in their name by default.)

Yes I do. I have each for test and ex47 folder. They worked for nosetest before but not now.

Wow, this is the exact problem.

“In those directories, search for test_*.py or *_test.py files, imported by their test package name.”

I named my test file with an s to the end so it collected nothing.
Thank you so much!

But I still don’t know why nosetest ran nothing. Do I have to work on that as well or leave it be?
I am not sure if I should focus on nosetest since so many people recommend pytest in this forum.

2 Likes

Thank you so much! @florian solved my problem. But I’ll keep your advice in mind!

My opinion? No need to waste time on it.

I ran into the same problem. Deleting the s solved it for me. But now I ran into the problem of my system not recognising the assertequal function, because it was imported from nose I suppose.

import pytest
from project47.game import Room

def test_room():
    gold = Room("GoldRoom",
                """This room has gold in it you can grab.
                There's a door to the north.""")
    assert_equal(gold.name, "GoldRoom")
    assert_equal(gold.paths, {})

def test_room_paths():
    center = Room("Center", "Test room in the center.")
    north = Room("North", "Test room in the north.")
    south = Room("South", "Test room in the south.")

    center.add_paths({'north': north, 'south': south})
    assert_equal(center.go('north'), north)
    assert_equal(center.go('south'), south)


def test_map():
    start = Room("Start", "You can go west and down a hole")
    west = Room("Trees", "There are trees here, you can go east.")
    down = Room("Dungeon", "It's dark down here, you can go up.")

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

    assert_equal(start.go('west'), west)
    assert_equal(start.go('west').go('east'), start)
    assert_equal(start.go('down').go('up'). start)

I get this error:

Yes pytest uses only plain assertions.

assert a == b