Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_vim: Failure with Python 3.13 #571

Closed
cryptomilk opened this issue Jun 14, 2024 · 3 comments · Fixed by #578
Closed

test_vim: Failure with Python 3.13 #571

cryptomilk opened this issue Jun 14, 2024 · 3 comments · Fixed by #578

Comments

@cryptomilk
Copy link
Contributor

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
Copy link
Member

justinmk commented Jun 19, 2024

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.

@justinmk
Copy link
Member

@cryptomilk any chance you can send a PR? Then we'll do a release #577 (comment)

@wookayin
Copy link
Member

The failing tests were written by me, I can send a PR very soon.

wookayin added a commit to wookayin/pynvim that referenced this issue Oct 31, 2024
Fixes neovim#571.

Problem: The `test_python3_ex_eval` test fails on python3.13 because the
format of stacktrace message has changed.

Solution: Check for important lines only.
wookayin added a commit that referenced this issue Oct 31, 2024
Fixes #571.

Problem: The `test_python3_ex_eval` test fails on python3.13 because the
format of stacktrace message has changed.

Solution: Check for important lines only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants