Commit ec929991 authored by Kirill Smelkov's avatar Kirill Smelkov

go: Fix test_go when running in-tree without pygolang being installed

This test was failing when pygolang was not dev-mode installed (`pip install -e .`):

	kirr@deco:~/src/tools/go/pygolang$ py.test
	=========================================== test session starts ============================================
	platform linux2 -- Python 2.7.15+, pytest-3.6.4, py-1.6.0, pluggy-0.6.0
	rootdir: /home/kirr/src/tools/go/pygolang, inifile:
	collected 8 items

	golang/_gopath_test.py ..                                                                            [ 25%]
	golang/gcompat_test.py .                                                                             [ 37%]
	golang/golang_test.py F....                                                                          [100%]

	================================================= FAILURES =================================================
	_________________________________________________ test_go __________________________________________________

	    def test_go():
	        # leaked goroutine behaviour check: done in separate process because we need
	        # to test process termination exit there.
	        subprocess.check_call([sys.executable,
	>           dirname(__file__) + "/golang_test_goleaked.py"])

	golang/golang_test.py:38:
	_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

	popenargs = (['/usr/bin/python2', '/home/kirr/src/tools/go/pygolang/golang/golang_test_goleaked.py'],)
	kwargs = {}, retcode = 1
	cmd = ['/usr/bin/python2', '/home/kirr/src/tools/go/pygolang/golang/golang_test_goleaked.py']

	    def check_call(*popenargs, **kwargs):
	        """Run command with arguments.  Wait for command to complete.  If
	        the exit code was zero then return, otherwise raise
	        CalledProcessError.  The CalledProcessError object will have the
	        return code in the returncode attribute.

	        The arguments are the same as for the Popen constructor.  Example:

	        check_call(["ls", "-l"])
	        """
	        retcode = call(*popenargs, **kwargs)
	        if retcode:
	            cmd = kwargs.get("args")
	            if cmd is None:
	                cmd = popenargs[0]
	>           raise CalledProcessError(retcode, cmd)
	E           CalledProcessError: Command '['/usr/bin/python2', '/home/kirr/src/tools/go/pygolang/golang/golang_test_goleaked.py']' returned non-zero exit status 1

	/usr/lib/python2.7/subprocess.py:190: CalledProcessError
	------------------------------------------- Captured stderr call -------------------------------------------
	Traceback (most recent call last):
	  File "/home/kirr/src/tools/go/pygolang/golang/golang_test_goleaked.py", line 23, in <module>
	    from golang import go, chan
	ImportError: No module named golang
	==================================== 1 failed, 7 passed in 0.10 seconds ====================================

Fix it by injecting top-level pygolang/ into $PYTHONPATH when testing
via external processes.

Fixes 69cef96e (go: Don't allow leaked goroutines to prevent program to exit)
parent ab69e0fa
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
from golang import go, chan, select, default, _PanicError, method from golang import go, chan, select, default, _PanicError, method
from pytest import raises from pytest import raises
from os.path import dirname from os.path import dirname
import sys, time, threading, inspect, subprocess import os, sys, time, threading, inspect, subprocess
# tdelay delays a bit. # tdelay delays a bit.
# #
...@@ -34,8 +34,20 @@ def tdelay(): ...@@ -34,8 +34,20 @@ def tdelay():
def test_go(): def test_go():
# leaked goroutine behaviour check: done in separate process because we need # leaked goroutine behaviour check: done in separate process because we need
# to test process termination exit there. # to test process termination exit there.
subprocess.check_call([sys.executable,
dirname(__file__) + "/golang_test_goleaked.py"]) # adjust $PYTHONPATH to point to pygolang. This makes sure that external
# script will succeed on `import golang` when running in-tree.
dir_golang = dirname(__file__) # .../pygolang/golang
dir_top = dir_golang + '/..' # ~> .../pygolang
pathv = [dir_top]
env = os.environ.copy()
envpath = env.get('PYTHONPATH')
if envpath is not None:
pathv.append(envpath)
env['PYTHONPATH'] = ':'.join(pathv)
subprocess.check_call([sys.executable, dir_golang + "/golang_test_goleaked.py"],
env=env)
def test_chan(): def test_chan():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment