• Kirill Smelkov's avatar
    *: Python3.9 switched __file__ to be always absolute · 4f28dddf
    Kirill Smelkov authored
    https://bugs.python.org/issue20443
    
    This broke test_defer_excchain_dump because
    testprog/golang_test_defer_excchain.txt is prepared with output where
    `python file` shows that file name in traceback as it was specified on
    the command line, e.g.
    
        .../pygolang/golang/testprog$ python golang_test_defer_excchain.py
        Traceback (most recent call last):
          File ".../pygolang/golang/__init__.py", line 103, in _
            return f(*argv, **kw)
          File "golang_test_defer_excchain.py", line 42, in main
            raise RuntimeError("err")
        RuntimeError: err
    
    while with py39 it became
    
        .../pygolang/golang/testprog$ python golang_test_defer_excchain.py
        Traceback (most recent call last):
          File ".../pygolang/golang/__init__.py", line 103, in _
            return f(*argv, **kw)
          File ".../pygolang/golang/testprog/golang_test_defer_excchain.py", line 42, in main
            raise RuntimeError("err")
        RuntimeError: err
    
    (notice the difference related to "line 42")
    
    -> Fix it:
    
    - amend the test to conditionally prefix golang_test_defer_excchain.py
      in expected output with PYGOLANG/golang/testprog/ if it is Python >= 3.9.
    - amend `gpython file` to match behaviour of underlying `python file`,
      so that the test passes unconditionally whether it is run by python or
      gpython.
    
    --------
    
    @jerome also says (!13 (comment 122826)):
    
    FYI, buildout (and many zope packages) essentially use doctests for
    testing and they had to deal with similar differences in output.
    `zope.testing` comes with a doctest checker named "renormalizing" which
    normalize output with regular expressions, see for example setup of some
    buildout test [here](https://github.com/buildout/buildout/blob/db3d6e2fbf5d7ff2cc4b2507253c7a221cfc3e32/src/zc/buildout/tests.py#L3615-L3651).
    We definitely don't need this here for the moment, but maybe one day it
    can be useful.
    
    /reviewed-on !13
    4f28dddf
golang_test_defer_excchain.txt 1.46 KB