Skip to content

Correct warnings that contains Unicode message #2437

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

Merged
merged 3 commits into from
May 26, 2017

Conversation

coldnight
Copy link
Contributor

@coldnight coldnight commented May 25, 2017

This PR try to fix #2436.

  • Target: master;

Unless your change is trivial documentation fix (e.g., a typo or reword of a small section) please:

  • Make sure to include one or more tests for your change;
  • Add yourself to AUTHORS;
  • Add a new entry to CHANGELOG.rst
    • Choose any open position to avoid merge conflicts with other PRs.
    • Add a link to the issue you are fixing (if any) using RST syntax.
    • The pytest team likes to have people to acknowledged in the CHANGELOG, so please add a thank note to yourself ("Thanks @user for the PR") and a link to your GitHub profile. It may sound weird thanking yourself, but otherwise a maintainer would have to do it manually before or after merging instead of just using GitHub's merge button. This makes it easier on the maintainers to merge PRs.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0008%) to 92.348% when pulling c39689d on coldnight:master into 17f6470 on pytest-dev:master.

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work

when seeing the actual impact in code, its a nice to have feature, but not without warning the user, that his code is broken

a test runner that hides breakages with a workaround does a disservice after all
it might be best to trigger a pytest warning while explicitly passing the file/lineno

@@ -62,7 +64,7 @@ def catch_warnings_for_item(item):

for warning in log:
msg = warnings.formatwarning(
warning.message, warning.category,
compat.safe_str(warning.message), warning.category,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its required to warn the user here that his warning message is broken as it is not a str instance (after all this is a stdlib problem wrokaround)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@@ -62,7 +64,7 @@ def catch_warnings_for_item(item):

for warning in log:
msg = warnings.formatwarning(
warning.message, warning.category,
compat.safe_str(warning.message), warning.category,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.



def test_unicode(testdir, pyfile_with_warnings):
testdir.makepyfile('''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! Please add a CHANGELOG entry as well. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know which section should I add the entry to CHANGELOG, could you please tell me that?

Copy link
Member

@nicoddemus nicoddemus May 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry did not realize we did not prepare the CHANGELOG for new entries.

Please add something like this to the CHANGELOG:

3.1.1 (unreleased)
==================

* Fix encoding errors for unicode warnings in Python 2.

We are introducing towncrier to manage the CHANGELOG in #2431, but we will take care of moving the entry to that format later! 👍

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 92.312% when pulling 53add44 on coldnight:master into 17f6470 on pytest-dev:master.

@coldnight
Copy link
Contributor Author

@RonnyPfannschmidt @nicoddemus r?

@nicoddemus
Copy link
Member

Excellent work, thanks a ton! 👍

Btw, would you like to be added to the AUTHORS file? And if so by which name?

@nicoddemus nicoddemus merged commit 8df3e55 into pytest-dev:master May 26, 2017
@coldnight
Copy link
Contributor Author

@nicoddemus Sure, that's my honor. Just use Hui Wang (coldnight) and thanks for your awesome work on pytest!

@nicoddemus
Copy link
Member

@coldnight done, thanks again! 😁

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

Successfully merging this pull request may close these issues.

UnicodeEncodeError in warnings capture
4 participants