Ex46 - Ran 0 tests Issue - Help!

Hello all, this is my first time posting and I need some help.

I have tried this exercise a few times. I have not had any other trouble in the book that I haven’t been able to research and figure out. I browsed the forum/internet before asking, but here it goes.

I go through ex 46 and follow the directions.

I have installed pip, virtualenv, nose, and setuptools.

Here is my directory structure.
test2
I created the init.py files for the tests and NAME directories.

The set up file and the NAME_tests.py file were copied by hand from the book and saved.

Just as a side not I added these files to their respective directories as well as the book describes.

I then start the virtual environment in Powershell with ..venvs\lpthw\Scripts\activate and get into the virtual environment that was created, cd to the skeleton directory, then try and run nosetests.

I cannot seem to get any other result than “Ran 0 tests in 0.008s.”

I am really struggling to see where I went wrong. Is it the new version of python I am using?

Did I make a glaring mistake?

I just want to figure out what i have messed up so I can move forward in the book and start reading the second book. I’m a huge fan of this book and Zed. If I left anything out and this post needs more detail please let me know. I appreciate any feedback I can get.

Let’s see, here’s some common things that happen:

  1. You named your file tests/_init_.py (single underscore) instead of tests/__init__.py (double underscore).
  2. Same for NAME/__init__.py
  3. You try to cd into tests when you should never do that.
  4. You think you wrote tests but you actually didn’t, probably by naming them wrong.

Drop some more screenshots of what happens when you run it, and what your ls tests and ls NAME directory says.

Thank you for responding Zed!

I checked the init file names for tests/names and they both have the double underscore.
I am trying to run nosetests from skeleton where all the other directories are located.

I think the NAME_tests.py file is correct. Here is a screenshot of my code.

I am a new user and cannot post more than one screenshot per post so I will post them in replies if that is okay.

Here is a screenshot of me running nosetests.

image

Here is a screenshot of ls tests.

image

Here is a screenshot of ls NAME.

image

Nosetests is so frustrating. Looking at your code vs. mine it looks the same, and mine runs, so here’s where the code is:

The only thing I can see if you might have a stale __pycache__ directory in tests/ so try deleting that. Then see if you can get my code and see if there’s a difference that I’m not seeing.

Last thing, did you save your NAME_tests.py file? Sometimes that’s it. It’s in your editor and looks fine, but on the disk it’s empty. Try this:

cat tests/NAME_tests.py

See if it is empty.

May I suggest Pytest instead of Nose?

The documentation is a little bit better.
I and some other have used pytest for testing in this exercise.

Search in this forum for ”pytest” and you will find some examples.

So I tried all this and doesn’t seem like it wants to work. I made sure the NAME_tests.py file was saved, deleted those pycaches and made sure it wasn’t empty. Still getting that 0 tests ran message. I talked to a developer at my job and he went through the project with me and wasn’t able to determine what was wrong either so I am just going to try Pytest and move forward. Thanks for your help and suggestions!

I looked up pytests and got it working. :smiley:

1 Like

I got the exactly same problem as you. Thank you very much! I will try pytest

Hello all, Hello Zed ,this is my first posting, too. I have tiried ex46 a few times , too. But I have the same trouble.I sure that i have checked all details. I have read this book by myself and overcomed all difficulties except ex46.
The only difference is my windows version .It is windows 7.
What should I do?

Hello all, Hello Zed ,this is my first posting, too. I have tiried ex46 a few times , too. But I have the same trouble.I sure that i have checked all details. I have read this book by myself and overcomed all difficulties except ex46.
The only difference is my windows version .It is windows 7.
What should I do?
Look up pytest?

Yes, try pytest. It will probably run smoothly out of the box. Life is too short to keep wrestling with nose.

I agree. If you want to keep native, checkout unittest but PyTest expands this anyway.

Thank you very much@

try this way…
enter in tests directory
Screenshot%20(2)

Don’t enter into the tests directory. Never ever do this:

cd test
nose

That won’t work. You have to be in the directory above.

Hello everyone,

I don’t know if you already solved this but just to add extra comments on the issue:
I had the same problem as everyone where I run nosetests and it always says 0 Tests run.

I tried several variations on how the files were created or how the files are structured and I’m not sure why, but it works in the following way:

  1. If I run it outside the virtual enviroment it always works with Zed’s structure.
  2. If I run it within the virtualenv it doesn’t work if I have the init.py file in the tests folder. If I remove it it works perfect within the virtualenv, but I am not sure why this happens.

Hope this helps someone,

Thanks

Hey @martincormack, I’m curious about when you say “works within the virtualenv”.

Do you mean you do something like this:

cd .venvs/myproject

And then work inside the virtual environment? Or, do you just mean that you activate the virtual environment, but your code lives in a totally different directory?