nanomsg/nnpy

test.py doesn't run

Opened this issue · 1 comments

OS: Kubuntu 20.04

To recreate:

git clone https://github.com/nanomsg/nnpy.git
cd nnpy/nnpy
python tests.py

This produces the output::

Traceback (most recent call last):
  File "tests.py", line 2, in <module>
    import filecmp, nnpy, sys, unittest
  File "build/bdist.linux-x86_64/egg/nnpy/__init__.py", line 2, in <module>
    from _nnpy import ffi, lib as nanomsg
  File "build/bdist.linux-x86_64/egg/_nnpy.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/_nnpy.py", line 3, in __bootstrap__
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 36, in <module>
    import email.parser
  File "/usr/lib/python2.7/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser
  File "/usr/lib/python2.7/email/feedparser.py", line 27, in <module>
    from email import message
  File "/usr/lib/python2.7/email/message.py", line 16, in <module>
    import email.charset
  File "/usr/lib/python2.7/email/charset.py", line 13, in <module>
    import email.base64mime
  File "/usr/lib/python2.7/email/base64mime.py", line 40, in <module>
    from email.utils import fix_eols
  File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
    import socket
  File "/home/nnpy/nnpy/socket.py", line 1, in <module>
    from . import errors, ffi, nanomsg
ValueError: Attempted relative import in non-package

This is because the directory that the tests are being run in takes precedence for imports and class declarations. This can be observed in the lines:

...
  File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
    import socket
...

There are three options:

  1. Move test,py to nnpy/
  2. Create an nnpy/test/ directory and move it there
  3. Create an nnpy/nnpy/test/ directory and move it there

I think option 3 is preferable

djc commented

Have you tried running python setup.py test from the top-level directory, instead?