• Kirill Smelkov's avatar
    golang: Don't keep test programs inside golang/ dir · 6e3b3ff4
    Kirill Smelkov authored
    Python adds dirname of run program to sys.path . This way when
    golang_test_goleaked.py runs it can import modules located under golang/
    just by their name. Until now this was not noticed, but in the next
    patch we are going to add golang.time module and if test program is run
    with golang/ in sys.path just plain `import time` won't import time from
    stdlib and instead import time from golang/ .
    Such behaviour can be mitigated by doing `from __future__ import
    absolute_import` and we do that, including in golang_test_goleaked.py
    (see 81dfefa0 "*: __future__ += absolute_imports; Use unified __future__
    everywhere"). However that does not prevent modules - even modules from
    stdlib - who are doing `import time` and not doing future
    absolute_import to import golang's time instead of stdlib. For example
    on PyPy2 threading imports time and then the test breaks:
      Traceback (most recent call last):
        File "/home/kirr/src/tools/go/pygolang/.tox/pypy-thread/site-packages/golang/golang_test_goleaked.py", line 24, in <module>
          from golang import go, chan
        File "/home/kirr/src/tools/go/pygolang/.tox/pypy-thread/site-packages/golang/__init__.py", line 38, in <module>
          import inspect, threading, collections, random, sys
        File "/usr/lib/pypy/lib-python/2.7/threading.py", line 15, in <module>
          from time import time as _time, sleep as _sleep
        File "/home/kirr/src/tools/go/pygolang/.tox/pypy-thread/site-packages/golang/time.py", line 30, in <module>
          from golang import go, chan, select, default, nilchan, panic
      ImportError: cannot import name 'go'
    -> Move the test program into a directory different from golang/ to
    avoid this trap.
Last commit
Last update
golang Loading commit data...
gpython Loading commit data...
.gitignore Loading commit data...
CHANGELOG.rst Loading commit data...
COPYING Loading commit data...
MANIFEST.in Loading commit data...
README.rst Loading commit data...
setup.py Loading commit data...
tox.ini Loading commit data...