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

@pytest.mark.parametrize handles escape characters differently for Python2 and Python 3 #24888

Closed
ziransun opened this issue Aug 5, 2020 · 7 comments

Comments

@ziransun
Copy link
Member

ziransun commented Aug 5, 2020

When calling @pytest.mark.parametrize in tests, if argument contains escape characters (e.g. \n, \t etc.), it produces different test names in PY2 and PY3.

Examples:

@pytest.mark.parametrize("text", [..., "Fed\terer"] produces test names 
test_send_alert_text[Fed erer] for PY2
test_send_alert_text[Fed\terer] for PY3

https://wpt.fyi/results/webdriver/tests/send_alert_text/send.py?diff&filter=ADC&run_id=632440001&run_id=619000003
https://wpt.fyi/results/webdriver/tests/find_element/find.py?diff&filter=ADC&run_id=632440001&run_id=619000003

This is very likely due to that in PY2 the default type for strings was str, but it was stored as byte while in PY3 str corresponds to unicode type. Python string literals treat backslashes as initiating escape sequences (e.g. \n is LF). For unicode, it retains characters as it is (e.g. '\n' is '\n').

It is also noted that @pytest.mark.parametrize expects str type arguments.

@Hexcles
Copy link
Member

Hexcles commented Aug 5, 2020

cc @jgraham could you take a look?

I think these test names are generated by pytest, so whatever escaping happens there. Is there anything we can do? Or would you (and other folks working on WebDriver) be fine with the change of test names? (To me, the PY3 representation seems more user-friendly.)

@gsnedders
Copy link
Member

I think this was a change in pytest after it went Python 3 only?

@jgraham
Copy link
Contributor

jgraham commented Sep 15, 2020

I'm not very worried by a small number of changes here.

@stephenmcgruer
Copy link
Contributor

Given that this is just a few (~10?) tests in webdriver/, and since the Py3 names are nicer than the Py2 names, I'm inclined to say this is WAI and accept the difference in test names until we're Py3-only (which is a long time away).

@gsnedders
Copy link
Member

It sounds like nobody is worried by this?

@stephenmcgruer
Copy link
Contributor

Yep; closing working as intended.

@ziransun - please note but ignore any diffs caused by this problem in your Py2/Py3 analysis work.

@ziransun
Copy link
Member Author

@ziransun - please note but ignore any diffs caused by this problem in your Py2/Py3 analysis work.

Updated the analysis worksheets.

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

No branches or pull requests

5 participants