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

pytest 3.2 breaks pytest.mark.parametrize with null bytes #2644

Closed
alex opened this Issue Aug 1, 2017 · 12 comments

Comments

Projects
None yet
5 participants
@alex
Contributor

alex commented Aug 1, 2017

(tempenv-543d64822ecc) ~/.v/tempenv-543d64822ecc ❯❯❯ pip install "pytest<3.2"
Collecting pytest<3.2
  Using cached pytest-3.1.3-py2.py3-none-any.whl
Requirement already satisfied: py>=1.4.33 in ./lib/python2.7/site-packages (from pytest<3.2)
Requirement already satisfied: setuptools in ./lib/python2.7/site-packages (from pytest<3.2)
Installing collected packages: pytest
  Found existing installation: pytest 3.2.0
    Uninstalling pytest-3.2.0:
      Successfully uninstalled pytest-3.2.0
Successfully installed pytest-3.1.3
(tempenv-543d64822ecc) ~/.v/tempenv-543d64822ecc ❯❯❯ cat test.py
import pytest


@pytest.mark.parametrize("data", ["\x00"])
def test_foo(data):
    assert data
(tempenv-543d64822ecc) ~/.v/tempenv-543d64822ecc ❯❯❯ py.test  test.py
====================================================== test session starts =======================================================
platform darwin -- Python 2.7.13, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /Users/alex_gaynor/.virtualenvs/tempenv-543d64822ecc, inifile:
collected 1 item s

test.py .

==================================================== 1 passed in 0.01 seconds ====================================================
(tempenv-543d64822ecc) ~/.v/tempenv-543d64822ecc ❯❯❯ pip install -U pytest
Collecting pytest
  Using cached pytest-3.2.0-py2.py3-none-any.whl
Requirement already up-to-date: py>=1.4.33 in ./lib/python2.7/site-packages (from pytest)
Requirement already up-to-date: setuptools in ./lib/python2.7/site-packages (from pytest)
Installing collected packages: pytest
  Found existing installation: pytest 3.1.3
    Uninstalling pytest-3.1.3:
      Successfully uninstalled pytest-3.1.3
Successfully installed pytest-3.2.0
(tempenv-543d64822ecc) ~/.v/tempenv-543d64822ecc ❯❯❯ py.test  test.py
====================================================== test session starts =======================================================
platform darwin -- Python 2.7.13, pytest-3.2.0, py-1.4.34, pluggy-0.4.0
rootdir: /Users/alex_gaynor/.virtualenvs/tempenv-543d64822ecc, inifile:
collected 1 item s

test.py EE

============================================================= ERRORS =============================================================
_________________________________________________ ERROR at setup of test_foo[] __________________________________________________

self = {'TERM_PROGRAM_VERSION': '3.0.15', 'LOGNAME': 'alex_gaynor', 'USER': 'alex_gaynor', 'HOME': '/Users/alex_gaynor', 'PAT..._ENCODING': '0x1F5:0x0:0x0', 'PWD': '/Users/alex_gaynor/.virtualenvs/tempenv-543d64822ecc', 'COMMAND_MODE': 'unix2003'}
key = 'PYTEST_CURRENT_TEST', item = 'test.py::test_foo[\x00] (setup)'

    def __setitem__(self, key, item):
>       putenv(key, item)
E       TypeError: putenv() argument 2 must be string without null bytes, not str

lib/python2.7/os.py:473: TypeError
________________________________________________ ERROR at teardown of test_foo[] ________________________________________________

self = {'TERM_PROGRAM_VERSION': '3.0.15', 'LOGNAME': 'alex_gaynor', 'USER': 'alex_gaynor', 'HOME': '/Users/alex_gaynor', 'PAT..._ENCODING': '0x1F5:0x0:0x0', 'PWD': '/Users/alex_gaynor/.virtualenvs/tempenv-543d64822ecc', 'COMMAND_MODE': 'unix2003'}
key = 'PYTEST_CURRENT_TEST', item = 'test.py::test_foo[\x00] (teardown)'

    def __setitem__(self, key, item):
>       putenv(key, item)
E       TypeError: putenv() argument 2 must be string without null bytes, not str

lib/python2.7/os.py:473: TypeError
==================================================== 2 error in 0.07 seconds =====================================================
(tempenv-543d64822ecc) ~/.v/tempenv-543d64822ecc ❯❯❯

alex added a commit to pyca/cryptography that referenced this issue Aug 1, 2017

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Aug 1, 2017

Thanks for the quick report @alex.

This is due to the new PYTEST_CURRENT_TEST environment variable which is set during testing. I will work on a fix ASAP.

@alex

This comment has been minimized.

Contributor

alex commented Aug 1, 2017

Yeah, looks like you'll want some sort of escaping scheme. (Maybe also truncation for really long values?)

@alex

This comment has been minimized.

Contributor

alex commented Aug 1, 2017

Thanks for jumping on this!

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Aug 1, 2017

reaperhulk added a commit to pyca/cryptography that referenced this issue Aug 1, 2017

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Aug 1, 2017

#2646 is up. This fix will be released in 3.2.1.

Thanks again for the quick report!

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Aug 2, 2017

While this is not released, a workaround is to set an id to the parametrized value:

import pytest
@pytest.mark.parametrize("data", [pytest.param("\x00", id='null')])
def test_foo(data):
    assert data

# alternatively
import pytest
@pytest.mark.parametrize("data", ["\x00"], ids=['null'])
def test_foo(data):
    assert data

This has the additional benefit of showing nicely on the terminal.

carver added a commit to carver/web3.py that referenced this issue Aug 2, 2017

cleaner formatting as a workaround for pytest 3.2.0 bug
@see pytest-dev/pytest#2644

No need to revert this when 3.2.1 is released, because it
provides a cleaner view in the pytest output

reaperhulk added a commit to reaperhulk/cryptography that referenced this issue Aug 3, 2017

@alex

This comment has been minimized.

Contributor

alex commented Aug 3, 2017

Is there a plan for when 3.2.1 will be released?

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Aug 3, 2017

Hi @alex, I was thinking about releasing 3.2.1 next Monday/Tuesday. Is that acceptable for you guys?

@alex

This comment has been minimized.

Contributor

alex commented Aug 3, 2017

@nicoddemus It actually doesn't affect us really, I'm asking because one of our distributors (Fedora Raw Hide) was complaining :-) /cc @tiran

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Aug 3, 2017

@alex thanks. @tiran does next Monday/Tuesday work for you?

@tiran

This comment has been minimized.

tiran commented Aug 3, 2017

@nicoddemus sure, that's fine with me. Thanks for your fix!

For rawhide I simply removed the test case. F26 has an older pytest version.

alex added a commit to pyca/cryptography that referenced this issue Aug 3, 2017

Blacklist pytest 3.2.0 because it breaks us (#3835) (#3844)
* Blacklist pytest 3.2.0 because it breaks us (#3835)

See upstream: pytest-dev/pytest#2644

* fix for latest flake8 (#3829)

patkan added a commit to python-escpos/python-escpos that referenced this issue Aug 4, 2017

patkan added a commit to python-escpos/python-escpos that referenced this issue Aug 4, 2017

ryanpetrello added a commit to ansible/tacacs_plus that referenced this issue Aug 9, 2017

@pnbat

This comment has been minimized.

pnbat commented Nov 28, 2017

It seems that the same issue occurs again with pytest 3.3. Our build was working fine with pytest 3.2.5 and now we get this:
> self.putenv(key, value) E ValueError: embedded null byte
Don't know if it also happens with parameterize, we are using yield_fixtures (for python 2 compatibility).

@The-Compiler

This comment has been minimized.

Member

The-Compiler commented Nov 28, 2017

@pnbat See #2957

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment