Commit 7faaecbc authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Fix defer traceback tests when run somewhere under symlink

Since realpath was used to find out pygolang dir, it will give different
prefix compared to what actual prefix of __file__ is if __file__ was
imported through some symlinked directory. And it is the actual
__file__ that is included into traceback - not its realpath'ed version.

This was breaking for example like this on py27-gevent tox tests:

    __file__:          '.../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py'
    dirname(__file__): '.../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang'
    PYGOLANG:          '.../pygolang/.tox/py27-gevent/lib/python2.7/site-packages'

    E           Failed: not equal:
    E           Differences (unified diff with -expected +actual):
    E               @@ -1,8 +1,8 @@
    E                Traceback (most recent call last):
    E               -  File "PYGOLANG/golang/golang_test.py", line ..., in test_defer_excchain_traceback
    E               +  File ".../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py", line 1360, in test_defer_excchain_traceback
    E                    alpha()
    E               -  File "PYGOLANG/golang/golang_test.py", line ..., in alpha
    E               +  File ".../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py", line 1357, in alpha
    E                    beta()
    E               -  File "PYGOLANG/golang/golang_test.py", line ..., in beta
    E               +  File ".../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py", line 1356, in beta
    E                    raise RuntimeError("gamma")
    E                RuntimeError: gamma

-> Fix it by not doing realpath'ification when detecting PYGOLANG
prefix.

Fixes: bb9a94c3 (golang: Teach defer to chain exceptions (PEP 3134) even on Python2)
parent fd2a6fab
......@@ -24,7 +24,7 @@ from golang import go, chan, select, default, nilchan, _PanicError, func, panic,
from golang import sync
from pytest import raises, mark, fail
from _pytest._code import Traceback
from os.path import dirname, realpath
from os.path import dirname
import os, sys, inspect, importlib, traceback, doctest
from subprocess import Popen, PIPE
import six
......@@ -1597,7 +1597,7 @@ def assertDoc(want, got):
got = got .decode('utf-8')
# normalize got to PYGOLANG
dir_pygolang = realpath(dirname(__file__) + "/..") # pygolang
dir_pygolang = dirname((dirname(__file__))) # pygolang/golang/golang_test.py -> pygolang
got = got.replace(dir_pygolang, "PYGOLANG")
# ^$ -> <BLANKLINE>
......
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