-
-
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
Properly escape test names when setting PYTEST_CURRENT_TEST environment variable #2646
Conversation
I wonder what other stuff null bytes in node IDs could break though... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs a followup as test ids should be ascii to begin with, if they are non-ascii then we messed up somewhere else
please lets add a comment that this is only a workaround so the real bug doesnt affect people directly
I think I think the proper solution for this is for |
Argh you guys are correct, it was a brain fart on my part: nodeids are already turned into I would not like to touch I changed it to only remove the null bytes from the string that will be set as environment variable, and only in Python 2. Let me know what you guys think. |
a valid change, but it will also mean that the ids we store will not match the real test name, in addition i suspect we cant really support ids with null bytes as they cant be properly transferred anywhere else or even entered from the cli |
_pytest/runner.py
Outdated
@@ -134,7 +135,11 @@ def _update_current_test_var(item, when): | |||
""" | |||
var_name = 'PYTEST_CURRENT_TEST' | |||
if when: | |||
os.environ[var_name] = '{0} ({1})'.format(item.nodeid, when) | |||
value = _ascii_escaped('{0} ({1})'.format(item.nodeid, when)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does this _ascii_escaped
call do anything here? I think it does nothing as we discovered, and if that's true, it should probably be removed to not cause further confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't push the changes yet (I wrote my comment meaning to push right away, but got dragged by other things).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed it
As discussed, node ids have already been "ascii" sanitized by the parametrization process
What do you mean by "will not"? I mean: we already "ascii escape" node ids for some time now, so I don't see why my PR changed this in any way.
I see what you mean, but as I said I'm not comfortable doing this in this PR (or in |
I agree with @nicoddemus, and I think it'd be a good idea to escape null bytes in node IDs in general (in Actually, this makes me wonder whether we should just escape all ASCII values before 0x20 (space)... Those are all "special" chars, and some of them invisible (but it also contains things like tab). |
Moved this discussion over to #2649 |
Fix #2644