-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
explicitly passed parametrize ids do not get escaped to ascii #1351
Comments
at second glace, this isbreaking as expected, print on python2 will break on unicode please verify |
No, The point is if pytest should always make sure that |
my understanding is, that currently node id's are native strings so bytes on python2 |
Sorry, my comment above is wrong - it should ensure they're always ascii-only native strings (i.e. bytes on Python 2), like it does with the autogenerated IDs. For example, with this from __future__ import print_function
def pytest_runtest_logreport(report):
if report.when == 'call':
print('\n nodeid: {!r}'.format(report.nodeid)) and this # encoding: utf-8
import pytest
@pytest.mark.parametrize('foo', ['büpf'])
def test_args(foo):
pass
@pytest.mark.parametrize('foo', ['a'], ids=['büpf'])
def test_ids(foo):
pass The autogenerated ID gets escaped to be ascii only, but not the
|
@hpk42 ping? im under the impression we should either ensure the id's are always ascii, since python is growing more international and identifiers are unicode in 3.x, i think we should support unicode node id's simply because that is what we will get in future |
I'd like to try this bug for my Outreachy application for pytest-html. What's the final conclusion on what parametrize should do with the |
FWIW, @RonnyPfannschmidt's proposal makes sense from my POV. |
a simplistic implementation needs to ensure a few details
we should always byte-escape non-aphanumeric id values that are byte strings |
@RonnyPfannschmidt in your proposal do you mean Python 2 and 3, or only for Python 2? Python 3 should we strive to support full unicode? |
for both - even if we support full unicode id's we still will run into problems on windows, osx and other things |
Displaying them in the terminal for example? |
yes, also they are sometimes used for filenames/lookup keys - making them consistent ascii text in all cases seems sensible simply to avoid platform issues on unicode boundaries |
Fair enough, sounds reasonable. Thanks! 😁 |
A draft pull request is up at #1463. |
New pull request targeted at features is up at #1470. |
Closing as the PR was merged |
If values in parametrize contain unicode bytes, they are escaped when generating the IDs, however if these same objects are provided via the
ids
argument, they are not escaped. As a result, the resulting IDs can't be used with pylib's XML/HTML generation.This was discovered and previously discussed in https://github.com/davehunt/pytest-html/pull/30
To reproduce, create a conftest.py with the following contents:
Then, create a test file with the following contents:
Run the test, and you will get the following traceback:
The text was updated successfully, but these errors were encountered: