Ex47 ran 0 tests [SOLVED]

So i am facing a problem with nosetests, it shows that there was 0 tests ran and there should be 3.

my directory is exactly the way it should be, and both ex47_tests and game .py files are written with 0 errors. I’m not sure what other information might be needed to resolve the issue, so ask if you need to know something else! :slight_smile:

are the init.py files supposed to be empty, or am i missing something?

Ooof, this one comes up a lot.

Honestly, don’t bother to make nose work. Use pytest.

1 Like

tried pytest, did not work either.

also, visual studio code does not detect any problems (except for unused imports, if i change from nose.tools import * -> from nose.tools import assert_equal those “warnings” dissappear, but wont make a difference in nosetests results)

Did pytest also not run any tests or did it report any errors?
Dumb question: You are running the test from the root folder, not from the tests folder, right?

I think we won’t be able to help any further without seeing the files and the folder structure.


No dumb questions! No errors, just didn’t run any tests. im running the test from the folder skeleton…

My attempt on the folder structure, hope this is understandable (underscores make the text emphasized etc, sorry for that)

\ bin
\ docs
\ ex47
… init.py (with double underscores both side)
… game.py
\ tests
… init.py (with double underscores both side)
\ setup.py

the text files are exact as in the book, i can copy them hen im home if needed.

Okay. Can you do two things for me?

  1. Post ex47_tests.py.
  2. Run Pytest from the skeleton directory and post the output?

Sure thing!

I have a strong feeling it doesn’t work because of something i might have done wrong during ex46, at first i got some error message in text editor for assert_equal, but i installed nose again and that seemed to fix things (tests i ran back then did not report any errors, outcome was the same as it is in the screenshot i attached here).

Since i am very very new to programming, i dont really know that much of it except for lpthw and lsthw (i did pick up some reading on programming, since i really dont learn things by memory, but through understanding) i did try to change import nose.tests → import pytest, and i tried running pytest with commands pytest and py.test, none of those actions made a difference in results.



Okay, I think I see why Pytest doesn’t work.

  1. You can’t use the assert functions from nose.tools with Pytest. Get rid of the nose import and transform every call to assert_equal to a plain assert statement, e.g. assert_equal(gold.name, "GoldRoom") becomes assert gold.name == "GoldRoom".
  2. Pytest doesn’t recognize the filename suffix _tests. Rename the test file to either ex47_test.py or test_ex47.py.

Let me know if this helps! :slight_smile:

I recommend that you read up a bit on Pytest here and particularly about the test discovery rules here.

This fixed it, thank you so much for the help AND for the helpful links!

Stay healthy!

1 Like

Also, don’t forget the classic mistake:

_init_.py <---- 1 underscore is not python


__init__.py <-- double underscore, as in a dunder score, is Python.

If you name anything with a single underscore it is always wrong.

1 Like

I can run tests with nose only from the root folder. Seems you have a straightforward solution for me! :slight_smile:

See this older post for a more complete description/brainstorming of my problem. EX46: nosetests ran 0 tests or ran 1 tests with Error - #18 by Messere87

P.S.: I know I have to install Pytest soon… I just want to understand.

Well you’re supposed to only run them from the root folder. If you’re doing:

cd tests/

Then that’s not correct. Stay above that.

Sorry, I mean having the test file itself in the root folder. That’s the only way I can get nosetests working(?).

No, that’s not what I meant. Nose should definitely run tests in subfolders.

(Imagine the chaos if you had a huge project with a few dozen test files right in the root folder!)

1 Like

Oh that’s very different. On windows try this:


Notice the . (dot period) at the end of that.

On OSX and Linux do:


I get “Missing expression after ‘.’ in the element of the pipeline.”

By the way I solved the “script not on PATH” problems reinstalling python via the python.org installer.

Installing Python directly via the Windows app store had caused problems because all the new packages I had installed were not on PATH. I had used “python setup.py install” command to make nose work.

Only remaining problem now being that I can run tests by placing the test file above “tests” folder.

Thanks Zed for all the advice.
I really appreciate.

1 Like