Skip to content

PYTEST_CURRENT_TEST explodes on windows where the env var limit is 32767 bytes #2951

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

Closed
3 of 4 tasks
jonathanunderwood opened this issue Nov 25, 2017 · 4 comments
Closed
3 of 4 tasks
Labels
platform: windows windows platform-specific problem type: bug problem that needs to be addressed

Comments

@jonathanunderwood
Copy link

  • Include a detailed description of the bug or suggestion
  • pip list of the virtual environment you are using
  • pytest and operating system versions
  • Minimal example if possible

I have a fixture defined like this:

@pytest.fixture(
    params=[
        (b''),
        (os.urandom(32 * 1024)),
        (b'0' * 1024),
    ]
)
def data(request):
    return request.param

This causes problems on Windows whenever a test uses that fixture, because pytest tries to stuff the parameter values into PYTEST_CURRENT_TEST, and the value of data is large such that the PYTEST_CURRENT_TEST env var would end up being larger than the maximum allowed size on windows (32767 bytes). Here's an example failure (on appveyor):

self = {'APPVEYOR_REPO_COMMIT_AUTHOR': 'Jonathan Underwood', 'VS100COMNTOOLS': 'c:\\Program Files (x86)\\Microsoft Visual Stu...C:\\Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files'}
key = 'PYTEST_CURRENT_TEST'
item = 'tests/test_block.py::test_threads2[e\\x17\\xcfK\\x9f\\xb3rw\\x82\\x1a\\x14\\xf1Wc\\xf9\\x99S\\xf6\\x1b\\xcd\\xe0,\\x8...\xc3\\xdeT\\x19\\xe4l\\xeeH\\xbd\\xba\\x1b\\xd3\\xaf\\x02\\xeb\\xfe\\xf4\\xc9\\xa7pA\\xc3I-mode11-store_size0] (setup)'
    def __setitem__(self, key, item):
>       putenv(key, item)
E       ValueError: the environment variable is longer than 32767 bytes

I think what's needed is some way of saying to pytest "use this alias for this parameter value when composing PYTEST_CURRENT_TEST", or "don't set PYTEST_CURRENT_TEST".

@RonnyPfannschmidt
Copy link
Member

@jonathanunderwood pytest.param(os.urandom(32 * 1024), id='random:32KB') should work

@nicoddemus i believe its a bug that we simply escape random binary data - we really should use a auto-id there at least

@jonathanunderwood
Copy link
Author

jonathanunderwood commented Nov 25, 2017

Thanks - can confirm that setting ids fixes the immediate issue. It would be great for users if this was handled more gracefully by pytest. Some things spring to mind:

  • catch the exception and truncate PYTEST_CURRENT_TEST, possibly testing for if it's running on windows (which has a short env var length than linux etc)
  • autogenerate ids for all parameters for which ids aren't specified eg. using the fixture name and a counter
  • Allow users to specify that PYTEST_CURRENT_TEST should not be generated with a command line flag

jonathanunderwood added a commit to python-lz4/python-lz4 that referenced this issue Nov 25, 2017
If ids are not specified for fixture params then pytest embeds
them directly in the PYTEST_CURRENT_TEST environment variable.
This causes problems when those parameters are large, as data
is, particularly on MS Windows where env vars are limited to
32 kB in length.

pytest-dev/pytest#2951
@RonnyPfannschmidt
Copy link
Member

@jonathanunderwood

altering the id on the exception is not possible as its set in stone bytheon

auto-generating the ids is what should happen, however in order to ensure better test id comprehension we do try to use a text representation if sensible, the case you are hitting is where we use a string representation where it is certainly not sensible

i have no opinion on adding a option/flag for this - i defer to @nicoddemus on that one

@The-Compiler
Copy link
Member

Duplicate of #6881 (closing this one because the other already has a PR associated with it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: windows windows platform-specific problem type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants