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

First i wanna say Thanks to Zed for LPTHW and what he conveyed in it. Before starting to learn with LPTHW i had totally no , yes no CS backgrounds. I finished another py course( PY4E by Charles Russell Severance) so everything went well until EX46.

I met dfferent Errors in EX46, from installing virtualenv to create and edit files in virtualenv( i thought setup.py and other scripts shouid edit in IDLE launched from powershell so that can be a real work in virtualenv) and even to set Administrator account in win10 . All these Errors spend me a whole day to fix. In the early morning of the second day, i repeated to follow the steps in EX46 and everything went in order automatically(strange, i don’t konw why) . All done!
Than i began to run test with nose.
My work env is win10 64 bit, powershell to input command, python 3.8 32bit, vs code and notepad.exe to edit .py files (everytime i try to use IDLE from powershell i got syntax Error)

so i had to get files ready and copied them to the skeleton and sub directory.
I ran nosetests but it ran 0 test, that means 0 test was found be nose? I googled the solution but not workd.

2019-11-15_100851

In order to fix it, i checked and dit:

  1. the structure of skeleton to ensure it is right like what shows in the book
  2. copy init.py to every folder in skeleton, even in docs and bin, which didn’t work
  3. i typed line by line the setup.py and NAME_tests.py in notepad, or in vs code and copied them to /skeleton and /skeleton/tests
  4. i checked and scanned in nose documentations but seems found nothing useful.
  5. i changed name of NAME_tests.py, it didn’t work
  6. i jumped to EX47, set game.py and ex47_tests.py ready and tested with nosetests, it didn’t work again.

I also had idea to set other new virtualenvs in other PATH, but didn’t do that because sort of tired.
Short before i editting this post i used nose -h to see if any command may help, -where can find tests in the dir, so i tried.

Didn’t i type in the command properly? I don’t know.

So now is the third day i got stuck in EX46, hope anyone who sees this post may offer a little help.

----------------------------------------update-------------------------------------------------------------------------
Update:

I used a sample to test if nose functions, and it did! And it did again!
111
222

Encouraged by the progress i rererepeated the steps in the book:

  1. set docs bin NAME tests, 4 folders in \skeleton;

  2. init.py in NAME and tests in NAME and tests
    3 create setup.py in \skeleton and NAME_tests in \skeleton\tests
    4 launch IDLE directly from win powershell, pasted code into setpy and NAME_tests and checked every letters in IDLE
    5 run nosetests and python -m nose command after i kept \skeleton clean by removing all pycache folders,the \skeleton structure is totally same with in the book

  3. perfectly i got nothing.

Now i totally do not know what to do.

---------------UPDATE2-------------------------------------------------------------
well, i just tried once again:

  1. rename /skeleton/tests/NAME_tests.py to /skeleton/tests/test_tests.py, and move
    it to /skeleton/, together with setup.py

2 run nosetests, succeed.

  1. rename test_tests.py back to NAME_tests.py, succeed.

  2. move test_tests.py back to /skeleton/tests, failed.

444

Confused about why this happens.

Thanks again!

Why you have put your skeleton directory in .venvs directory?

Because it’s not important and makes no difference as long as in the virtualenv, and i tried to move it out of.venvs directory, got the same result as i guessed.

Are you changing the packages to import the correct folder in your setup.py?

Yes, so you have a few problems in how you’re doing this that stem from doing it slightly differently:

  1. Like @amisha12 said, I don’t put it in .venvs and nobody else puts anything in .venvs except packages downloaded from pip.
  2. Your IDLE install failing tells me you’ve got py2 and py3 installed. See #4.
  3. You’re typing nose [NOSE_WHERE] but I don’t type that.
  4. You have py3 and py2 installed at the same time which will cause problems. I’d remove py2 for now if you can. Otherwise, when you setup your virtualenv is when you force it to use py3.
  5. I’m not sure why you’re using python -m idlelib for anything. Again, I’d just skip that.

So I think a big part of your problem is py2 and py3 installed. Can you do this:

python --version
python3 --version

You should share screenshots of your test_test.py and your setup.py. I’d be happy to help more

Thanks to @amisha12 @Swervin! I’ll share my screenshots of setup.py and NAME_tests.py below.
And thanks @zedshaw for checking and replying this post. I’m the one who wrote you a email with doc in attachment that you don’t open.

I think the solution to this problem should be: never leave Name_tests.py in sub directory of \skeleton, because i found the same questions on stackflow:(you can check https://stackoverflow.com/questions/11263343/cannot-run-tests-with-nosetests)

That’s why i used -w command (but i failed because of kinds of akward reasons)

Now please have a little patience before we end this problem.

Well i had never ever used py2.x before, only py3.8.
2019-11-17_090751

I trieds as @amisha12 said aggin, delete all unnessary directories under .venvs, than i recreate projects directory and sub directories.

2019-11-17_091334

In \tests and \Name i creat init.py correctly, that’s no problem. So the only problem is NAME_tests.py.

Below is screenshots of setup.py and NAME_tests.py:

Than i ran nosetest directly from \skeleton, not from \skeleton\tests, than it ran 0 tests again:
2019-11-17_092450

Because i saw zed’s reply in other posts, so i tried to change Name_tests, and every other thing related to NAME to other names. Name directory now is changed to game, NAME_tests is changed to another name, whatever it is, not important. I rewirte the test.py:
from nose.tools import *
import game

Nosetests still ran 0 files.(No matter what i did above is right or wrong, the result never changed)

So i had no choice again. I ran nosetests again, fail. Than i move Name_tests.py out of \tests, directly under \skeleton, this time nosetests succeed.


Maybe my laptop has something wrong, or maybe some other uncommon reasons, perhaps i can never fix this problem, i don’t care it anymore.

The only question is: Name_tests in \skeleton, and Name_tests in \skeleton\tests, do this two different paths make a REAL Difference?

If it doesn’t, than we can leave it alone, but if it does, seems i need to write it down and try to fix it in the future learning.

Thaks @amisha12 @Swervin @zedshaw again.

you seem to be trying quite a few things between replies. I don’t always understand what you are saying, as sometimes your screenshots look different from what you said you did as far as renaming your directory structure. I have an idea. my email is [redacted]. you can send me an email and I’ll send you a rar of my working file directory for skeleton. If you extract that and then run nosetests and it still doesn’t work we will know it is an environmental issue on your system. Otherwise you are probably typing things wrong. Another couple side notes in your setup.py. I see that your typing is slightly off from ‘download_url’ on. Also in your NAME_tests.py your second def is teardonw its suppose to be teardown. I don’t think that’s the issue, but just figured id point it out.

1 Like

Thanks @Swervin for offering his working directory.

I finally got this issue fixed by deleting everything related to python, than installing python 3.6.0 and nose and virtualenv in the same version as in the book, restarting from the very beginning.
Finally nosetests went back and succeed in finding test files and running tests.

Maybe i’ll never consider updating neweset version of python and pips.

For what it’s worth, when I went through LPTHW I only tried nose once or twice and then switched to pytest, because Zed wrote that nose is no longer actively developed. I’m still using it (with Python 2 and 3 on my computer) and I haven’t had any problems like these. (It’s not difficult to rewrite existing tests, and the documentation is excellent.)

1 Like

Hi @Swervin, thanks for offering to do this but please don’t:

  1. Post your email address on the public forum. There’s a private message feature.
  2. Send unsolicited RAR, ZIP, PDF, or DOC files to people, or receive them from someone else. This is how people get viruses and RATs.

I don’t think you were going to do #2 but I’m posting that as a general warning to everyone since many people here are unsophisticated computer users and might not know those files are dangerous.

Just to say that I’ve been having exactly the issue that Dorsche has, with:

  • Python 3.8.1
  • Pip 19.3.1
  • nose 1.3.7
  • setuptools 42.0.2
  • virtualenv 16.7.9
  • wheel 0.33.6

By the same issue I mean that when I run nosetests I get the Ran 0 tests error as follows.

(lpthw) PS C:\Users\****\lpthw\projects\skeleton> nosetests
----------------------------------------------------------------------
Ran 0 tests in 0.003s
 
OK

Given the solution seems to be to revert to Python 3.6.0 is there a work-around / updated code for this?

P.S. to this point the book has been great - just a bit lost now.

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.)

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.

A free service run by Zed A. Shaw for learncodethehardway.org.