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

Parameterized test fail when test-data is a string containing null-bytes. #2973

Closed
bjornars opened this issue Nov 29, 2017 · 2 comments
Closed

Comments

@bjornars
Copy link

This was introduced by #2734, and released in 3.3 (specifically 78a027e)

Repro:

import base64                              
import pytest                              


def convert(data):                         
    return base64.b16encode(data).lower().decode()                                    


@pytest.mark.parametrize('data,expected', [                                           
    (b'\0\0\0\0', '00000000'),             
])                                         
def test_convert(data, expected):          
    assert convert(data) == expected  

Error:

self = environ({'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus'})            
key = b'PYTEST_CURRENT_TEST', value = b'test_repro.py::test_convert[\x00\x00\x00\x00-00000000] (setup)'                                                                      

    def __setitem__(self, key, value):     
        key = self.encodekey(key)          
        value = self.encodevalue(value)    
>       self.putenv(key, value)            
E       ValueError: embedded null byte     

../virtenv/test-venv/lib/python3.5/os.py:731: ValueError                                   

An educated guess would be that the parameterized arguments end up in the os.environ in some way, and that fails when the string contains embedded null-bytes. This was exposed with the above mentioned commit changing how strings were escaped and cleaned.

@The-Compiler
Copy link
Member

Duplicate of #2957

@The-Compiler The-Compiler marked this as a duplicate of #2957 Nov 29, 2017
@The-Compiler
Copy link
Member

Note that a fix is already available in the master branch: #2969

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

No branches or pull requests

2 participants