Discussion:
[Twisted-Python] trial cant find my class, example from twisted docs
steven meiers
2017-02-20 13:02:14 UTC
Permalink
hi,


up to now ive only used the python unittest for my code, but now i
would also like to test the twisted part.


so i followed:
http://twistedmatrix.com/documents/current/core/howto/trial.html


but i get this error:
(venv) ***@t560:~/code/python/twisted/basics$ trial calculus
calculus
...                                                            [ERROR]

=======================================================================
========
[ERROR]
Traceback (most recent call last):
  File
"/home/julius/code/python/twisted/basics/calculus/venv/lib/python3.5/si
te-packages/twisted/trial/runner.py", line 781, in loadByName
    return self.suiteFactory([self.findByName(name, recurse=recurse)])
  File
"/home/julius/code/python/twisted/basics/calculus/venv/lib/python3.5/si
te-packages/twisted/trial/runner.py", line 710, in findByName
    obj = reflect.namedAny(name)
  File
"/home/julius/code/python/twisted/basics/calculus/venv/lib/python3.5/si
te-packages/twisted/python/reflect.py", line 306, in namedAny
    raise ModuleNotFound("No module named %r" % (name,))
twisted.python.reflect.ModuleNotFound: No module named 'calculus'

calculus
---------------------------------------------------------------------
----------
Ran 1 tests in 0.024s

FAILED (errors=1)





heres how my calculus directory looks like:
find . | grep -v './venv/'
.
./__pycache__
./__pycache__/__init__.cpython-35.pyc
./test
./test/test_base_1.py
./test/__init__.py
./venv
./__init__.py
./base_1.py
./__init__.pyc



venv contains the virtualenv created by "virtualenv -p /usr/bin/python3
venv"


the __init__.py files are empty and test_base_1.py / base_1.py contains
what is shown in the tutorial.


any idea why this does not work?
Glyph Lefkowitz
2017-02-21 02:16:31 UTC
Permalink
Post by steven meiers
any idea why this does not work?
Most likely you are being bitten by the recent change to not add '.' to sys.path automatically.

Does `PYTHONPATH=. trial ...` run your code as expected?

-g
steven meiers
2017-02-21 10:08:33 UTC
Permalink
Post by Glyph Lefkowitz
Post by steven meiers
any idea why this does not work?
Most likely you are being bitten by the recent change to not add '.'
to sys.path automatically.
Does `PYTHONPATH=. trial ...` run your code as expected?
Yes, thanks very much. this kind of change really makes one doubt ones
abilities.

Should i write a ticket for this?



greetings
Hynek Schlawack
2017-02-21 10:34:05 UTC
Permalink
Post by steven meiers
Post by Glyph Lefkowitz
Post by steven meiers
any idea why this does not work?
Most likely you are being bitten by the recent change to not add '.'
to sys.path automatically.
Does `PYTHONPATH=. trial ...` run your code as expected?
Yes, thanks very much. this kind of change really makes one doubt ones
abilities.
Should i write a ticket for this?
No, you should start installing your packages and applications in dev lest packaging errors come back in prod and bite you. :)

More on that: https://hynek.me/articles/testing-packaging/

Loading...