EX46: nosetests ran 0 tests or ran 1 tests with Error

I can’t help you fix that error, but…

In the nose documentation I found this:

Nose has been in maintenance mode for the past several years and will likely cease without a new person/team to take over maintainership. New projects should consider using Nose2, py.test, or just plain unittest/unittest2.

Maybe try using another framework? (As I said earlier, I’m using pytest and it seems to just work.)

1 Like

Hello.

I changed to pytest quickly because of lack of good information (suitable for beginners).

Have a look at: Pytest instead of Nose for ex47 how I did the test.
You can also search for pytest in this forum for more information how to do.
I hope that helps you get going with the tests.

Thanks @ulfen69 that is helpful stuff. I had to run it file by file but it does show me the errors it worries about! For reference, I get the following:

    PS C:\Users\****\lpthw\projects\ex47\tests> pytest ex47_tests.py
======================================================== test session starts ========================================================
platform win32 -- Python 3.8.1, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\****\lpthw\projects\ex47
collected 3 items

ex47_tests.py FFF                                                                                                              [100%]

============================================================= FAILURES ==============================================================
_____________________________________________________________ test_room _____________________________________________________________

    def test_room():
        gold = Room("GoldRoom",
                    """This room has gold in you can grab.  There's a
                    door to the north.""")
>       assert_equal(gold.name, "GoldRoom")
E       NameError: name 'assert_equal' is not defined

ex47_tests.py:9: NameError
__________________________________________________________ test_room_paths __________________________________________________________

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

        center.add_paths({'north': north, 'south': south})
>       assert_equal(center.go('north'), north)
E       NameError: name 'assert_equal' is not defined

ex47_tests.py:18: NameError
_____________________________________________________________ test_map ______________________________________________________________

    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 = Rooom("Dungeon", "It's dark down here, you can go up.")
E       NameError: name 'Rooom' is not defined

ex47_tests.py:24: NameError
========================================================= 3 failed in 0.08s =========================================================

Hello @Vonron

From what I can see in your test result it looks like Nosetest code.

Pytest allmost allways use only “assert”

You wrote assert_equal in test_room() and test_room_paths().

I guess that:

assert gold.name == ”Goldroom"

would work for you in test_room().

And in test_room_paths()

assert_equal(center.go('north'), north)
# could be replaced by:
assert center.go('north') == "north"

In test_map() you have three “o” in “Room”
Look for the “>” and “E” in the output.
They tell you what the problem is about.
Or at least where it is.

I think you went down a huge rabbit hole here regarding tests and directories, but really the problem is a simple indentation error. Looking at the image, it looks like you have:

try:
   from setuptools import setup
except ImportError:
   # right here something is wrong with your indentation

I’m going to make a wild guess that you have some kind of spaces and tabs going on. Try deleting all the spaces in front of the two from...import lines, and look for other ways you can have bad spacing there.

I had the same problem as @Dorsche. I have Python 3.8.2. My tests run only if my test file is right in the same folder as setup.py, bin, docs, tests, NAME, while 0 tests run if I put the testfile in the tests folder as indicated.
There are no signs of Python2 installed.

I also wonder that was because I created a file NAME_tests.py inside tests… instead of creating a tests/NAME_tests.py. Could that be why? (I guess it is exactly the same thing.)

I had to face other issues going through ex46, while installing nose. I am not sure I can mount a virtual environment properly since when I install/uninstall any packages, I can see python38/scripts folder change.

I couldn’t have nosetests working until I typed “python setup.py install”.

I have the feeling that this command wasn’t the right thing to do.

Anyway I refuse to switch to 3.6 version to fix any problem because I don’t think I would learn anything from that. :grinning:

Some things to check:

  1. tests/NAME_tests.py is not executable. nose will skip it if it is.
  2. you have a __init__.py file in that directory. That’s double underscore init double underscore dot py.

Try those.

Thank you @zedshaw for calling out the __init__.py file in the /tests directory. This file is created during Exercise 46 with the command: $ new-item -type file tests/__init__.py

This seems to be a problem with Python 3.8.1 on Windows 10 64bit and removing it from the /tests directory allows nosetest to run successfully.

I haven’t gotten past ex47 yet, so don’t know if __init__.py is needed for further exercises, but it does seem to be a problem for nosetest.

Update
In further testing with Exercise 47, I see that __init__.py is required in the /ex47/ex47/ directory for the test script to call game.py. But, if there is a __init__.py file in /ex47/tests/ then it appears redirect nosetest because when you run nosetest the result is always Ran 0 tests in 0.000s.

Deleting the __init__.py in /ex47/tests/ allows ex47_tests.py to call /ex47/ex47/game.py when nosetest is run and the result is something like this: Run 3 tests in 0.0.10s.

Wait, what? So on windows would you say this is the test procedure:

  1. Create ex47/tests/__init__.py file.
  2. Create ex47/ex47/__init__.py file.
  3. Create ex47/tests/simple_test.py and have it import ex47.game.
  4. nosetests runs nothing.
  5. Delete ex47/tests/__init__.py file.
  6. nosetests runs simple_test.py.

If that’s true I have questions:

  1. Why are all your paths in this “ex47/”? Are you inside that directory or above it?
  2. Is there a way you can craft up two directories with just this as a demo? One nosetests fails and one that it runs in? If you can then I’d love to get it to figure out what’s going on.

@zedshaw Yes. That’s exactly the steps.

My environment is Windows 10 64bit, Python 3.8.1, nosetests version 1.3.7, PowerShell version 5.1.18362.752.

I’m always running nosetests from the root of the project directory as shown below.
This is my initial result after completing exercises 46 & 47 with problem file shown:
C:\USERS\HAWK_FW\PYTHON\PROJECTS\EX47
│ setup.py

├───bin
├───docs
├───ex47
│ │ game.py
│ │ __init__.py
│ │
│ └───__pycache__
├───tests
| │ ex47_tests.py
| │ __init__.py <-------Problem File
| │
| └───__pycache__

(lpthw) PS C:\Users\Hawk_fw\python\projects\ex47> nosetests

----------------------------------------------------------------------
Ran 0 tests in 0.007s

OK

As requested I created two new projects and tested them. The first one works and the second one fails.

First test:
C:\USERS\HAWK_FW\PYTHON\PROJECTS\TEST01_WORKS
│ setup.py

├───bin
├───docs
├───ex47
│ │ game.py
│ │ __init__.py
│ │
│ └───__pycache__
├───tests
| │ ex47_tests.py
| │
| └───__pycache__
(lpthw) PS C:\Users\Hawk_fw\python\projects\test01_works> nosetests
...
----------------------------------------------------------------------
Ran 3 tests in 0.016s

OK

Second test:
C:\USERS\HAWK_FW\PYTHON\PROJECTS\TEST02_DOES_NOT_WORK
│ setup.py

├───bin
├───docs
├───ex47
│ │ game.py
│ │ __init__.py
│ │
│ └───__pycache__
├───tests
| │ ex47_tests.py
| │ __init__.py
| │
| └───__pycache__
(lpthw) PS C:\Users\Hawk_fw\python\projects\test02_does_not_work> nosetests

----------------------------------------------------------------------
Ran 0 tests in 0.016s

OK

I’d be happy to send you both project test directories and files if you have an upload location and format preference.

That’s so weird. Why in the world would that cause nostests to fail like that?

If you are into using the better new testing thing, then replace nose with https://docs.pytest.org/en/latest/

Pytest works great! Thanks for the suggestion; I’ll keep using it in favor of nose.

The only change I had to make was to change the name of the test file from *_tests.py to *_test.py and pytest worked straight out of the box.

1 Like

I had the same problem described by the OP. Resolved by moving the NAME_tests.py out of the tests directory into the skeleton directory. Will switch to pytest.

Thank you.

image

I also have this problem with nosetests running 0 tests.

I have removed the init.py file from ./skeleton/tests, and this returns an error BUT it runs 1 test. When I create the init.py file in ./skeleton/tests, ‘nosetests’ runs 0 tests.

Has a solution to this problem been found?

I have checked that the venv directory contains the script nosetests (it does). I have checked that .venvs/lpthw/Lib/site-packages/nose/tools contains scripts to import. I have tried running nosetests from all levels of the directory with no luck. I have carefully repeated the entire exercise multiple times.

Edit: I tried moving NAME_tests.py to the parent directory, ./skeleton/, and this successfully runs 1 test, BUT only when I run nosetests from ./skeleton. It does not run a test when I run it from ./skeleton/tests. This makes sense, but I am not sure why it would not run when NAME_tests.py when it was in ./skeleton/tests.

I am genuinely stuck…

Honestly, the best way to unstuck yourself is by switching to Pytest. You are wasting your time with Nose.

Thanks for the suggestion! I will switch once I reach that point in the book, and from what I’ve read, continue to use it for that point forwards.

I agree with that. Nose has died since I wrote the book and pytest is just easier.

Thanks to @florian issue was resolved (by switching to pytest, lol). Not sure, at least now, how to properly read its output though.

Mr. @zedshaw since tool described in your book is obsolete now, maybe it will be helpful to create and pin a post about Pytest and basics of it’s usage? Like you pinned a forum rules.
Sort of “appendix” to ex.46.

I would if I had time but I’ve honestly been moving on Python entirely because of these very problems. If I ever finish my other work I’ll consider a rewrite of Python.

Thanks bro
The way you suggested worked for me as well