Search code examples
pythonnosenosetests

Nose complaining in Python 3 but not 2


I wrote tests using Python's unittest framework and ran them using Nose in Python 2.7 on Win7 x64 and they work fine:

D:\Users\Nick\Local HG\Waldo\code\shared\collider>py -2 -mnose
.............
----------------------------------------------------------------------
Ran 13 tests in 0.039s

OK

However, when I run them under Python 3.4, I get an inexplicable error

D:\Users\Nick\Local HG\Waldo\code\shared\collider>py -3 -mnose
E
======================================================================
ERROR: Failure: ValueError ('D:\\Users\\Nick\\Local HG\\Waldo\\code\\shared\\__init__.py\\__init__.pyw\\__init__.pyc' is
 not a package)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\nose\failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "D:\Python34\lib\site-packages\nose\loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "D:\Python34\lib\site-packages\nose\importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "D:\Python34\lib\site-packages\nose\importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "D:\Python34\lib\imp.py", line 245, in load_module
    return load_package(name, filename)
  File "D:\Python34\lib\imp.py", line 210, in load_package
    raise ValueError('{!r} is not a package'.format(path))
ValueError: 'D:\\Users\\Nick\\Local HG\\Waldo\\code\\shared\\__init__.py\\__init__.pyw\\__init__.pyc' is not a package

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

My package structure is:

collider\
  |- tests\
  |    |- __init__.py
  |    |- test_removing_chains.py
  |
  |- __init__.py
  |- collider.py
  |- viz.py

I don't know where the "...\\__init__.py\\__init__.pyw\\__init__.pyc" bit is coming from in the error, or why it's even going up a folder (\collider gets axed from the path apparently) even though I'll run the program in either the package root or from within the \tests folder (same error).


Solution

  • After removing superfluous __init__.py and .pyc files up a couple paths as suggested the problem went away.

    Unfortunately, however, I removed a bunch at once and adding them back in one-by-one didn't recreate the problem so I couldn't isolate what was the key point of failure.