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

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.

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