neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.47k stars 118 forks source link

test_vim: Failure with Python 3.13 #571

Open cryptomilk opened 2 weeks ago

cryptomilk commented 2 weeks ago

Hi,

I'm trying to fix pynvim with Python 3.13 which is in Fedora Rawhide (upcoming 41). The failure I get is:

=================================== FAILURES ===================================
_____________________________ test_python3_ex_eval _____________________________                                                                                                    

vim = <pynvim.api.nvim.Nvim object at 0x7f2b5e068950>

    def test_python3_ex_eval(vim: Nvim) -> None:                                
        assert '42' == vim.command_output('python3 =42')                                                                                                                            
        assert '42' == vim.command_output('python3 =   42     ')                
        assert '42' == vim.command_output('py3=    42     ')                                                                                                                        
        assert '42' == vim.command_output('py=42')

        # On syntax error or evaluation error, stacktrace information is printed
        # Note: the pynvim API command_output() throws an exception on error
        # because the Ex command :python will throw (wrapped with provider#python3#Call)
        with pytest.raises(NvimError) as excinfo:        
            vim.command('py3= 1/0')                                                       
>       assert textwrap.dedent('''\                                                       
            Traceback (most recent call last):                                                                                                                                      
              File "<string>", line 1, in <module>                                                                                                                                  
            ZeroDivisionError: division by zero
            ''').strip() in excinfo.value.args[0]                                                                                                                                   
E       assert 'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\nZeroDivisionError: division by zero' in 'function provider#python3#Call, line 1: Vim(ret
urn):E5108: Error executing lua Vim:Error invoking \'python_execute\' on channel 3 (python3-script-host):\nTraceback (most recent call last):\n  File "<string>", line 1, in <module
>\n    import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; neovim.start_host()\n    ^^^\nZeroDivisionError: division by zero\nstack traceback:\n\t[C]: at 0x55bb
fd9c11af'                                                                                                                                                                           
E        +  where 'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\nZeroDivisionError: division by zero' = <built-in method strip of str object at 0x7f2b
5e0752f0>()
E        +    where <built-in method strip of str object at 0x7f2b5e0752f0> = 'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\nZeroDivisionError: divisi
on by zero\n'.strip
E        +      where 'Traceback (most recent call last):\n  File "<string>", line 1, in <module>\nZeroDivisionError: division by zero\n' = <function dedent at 0x7f2b5f868ae0>('   
     Traceback (most recent call last):\n          File "<string>", line 1, in <module>\n        ZeroDivisionError: division by zero\n        ')
E        +        where <function dedent at 0x7f2b5f868ae0> = textwrap.dedent

test/test_vim.py:233: AssertionError

The traceback looks different now.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; neovim.start_host()
    ^^^
ZeroDivisionError: division by zero

My current fix is for Fedora is:

Index: pynvim-0.5.0/test/test_vim.py
===================================================================
--- pynvim-0.5.0.orig/test/test_vim.py  2024-06-14 08:47:38.588584340 +0200
+++ pynvim-0.5.0/test/test_vim.py       2024-06-14 09:00:22.910093156 +0200
@@ -231,8 +231,6 @@ def test_python3_ex_eval(vim: Nvim) -> N
     with pytest.raises(NvimError) as excinfo:
         vim.command('py3= 1/0')
     assert textwrap.dedent('''\
-        Traceback (most recent call last):
-          File "<string>", line 1, in <module>
         ZeroDivisionError: division by zero
         ''').strip() in excinfo.value.args[0]

@@ -240,9 +238,6 @@ def test_python3_ex_eval(vim: Nvim) -> N
     with pytest.raises(NvimError) as excinfo:
         vim.command_output('python3 =print("nooo", raise_error())')
     assert textwrap.dedent('''\
-        Traceback (most recent call last):
-          File "<string>", line 1, in <module>
-          File "<string>", line 1, in raise_error
         RuntimeError: oops
         ''').strip() in excinfo.value.args[0]
     assert 'nooo' not in vim.command_output(':messages')

Not sure if this is how you would like to address this.

justinmk commented 1 week ago

That seems fine to me. The stacktrace in all cases isn't particularly useful. @wookayin ?

If it's not much trouble, maybe also check for Traceback (most recent call last): but ignore the actual trace.