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

Use safe_str() to format warning message about unicode in Python 2 #4195

Merged
merged 2 commits into from
Oct 19, 2018

Conversation

nicoddemus
Copy link
Member

Fix #3691

src/_pytest/warnings.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 19, 2018

Codecov Report

Merging #4195 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4195      +/-   ##
==========================================
+ Coverage   95.72%   95.81%   +0.09%     
==========================================
  Files         109      109              
  Lines       24244    24327      +83     
  Branches     2390     2406      +16     
==========================================
+ Hits        23207    23310     +103     
+ Misses        736      721      -15     
+ Partials      301      296       -5
Flag Coverage Δ
#docs 28.5% <0%> (?)
#doctesting 28.5% <0%> (?)
#linting 28.5% <0%> (?)
#linux 95.59% <100%> (ø) ⬆️
#nobyte 91.84% <100%> (+0.61%) ⬆️
#numpy 92.87% <100%> (+51.58%) ⬆️
#pexpect 41.27% <0%> (-0.02%) ⬇️
#py27 93.9% <100%> (-0.04%) ⬇️
#py34 92.19% <40%> (+0.12%) ⬆️
#py35 92.2% <40%> (+0.12%) ⬆️
#py36 93.86% <40%> (+0.12%) ⬆️
#py37 92.26% <40%> (+0.02%) ⬆️
#trial 92.87% <100%> (+51.58%) ⬆️
#windows 94.04% <100%> (+3.03%) ⬆️
#xdist 93.79% <100%> (+0.16%) ⬆️
Impacted Files Coverage Δ
src/_pytest/warnings.py 88.31% <ø> (ø) ⬆️
testing/test_warnings.py 98.55% <100%> (+0.05%) ⬆️
testing/test_collection.py 99.76% <0%> (ø) ⬆️
src/_pytest/compat.py 96.77% <0%> (+0.22%) ⬆️
testing/acceptance_test.py 98.26% <0%> (+1.08%) ⬆️
src/_pytest/capture.py 93.82% <0%> (+1.37%) ⬆️
src/_pytest/assertion/util.py 98.11% <0%> (+5.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 61080da...864d7fe. Read the comment docs.

@nicoddemus
Copy link
Member Author

What is happening with Travis that it is creating two builds for each PR, cancelling one of them immediately?

image

@asottile
Copy link
Member

What is happening with Travis that it is creating two builds for each PR, cancelling one of them immediately?

image

idk, I've been seeing this only for pytest for the last couple of weeks. Sometimes it cancels the wrong build too and then you have to manually restart it 🤦‍♂️

@nicoddemus
Copy link
Member Author

Fixed the Travis issue, apparently 🎉 (#4197 and #4198)

@asottile
Copy link
Member

nice! what was the trick? (also fyi kinda neat feature of git: git commit --allow-empty ...)

@@ -18,7 +18,7 @@ envlist =

[testenv]
commands =
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest --lsof
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest --lsof {posargs}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need {posargs} here? Left over from local testing?

Copy link
Member

Choose a reason for hiding this comment

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

@Zac-HD without posargs its impossible to run specific tests in calls like tox -- testing/test_some.py since it wouldnt pass on

@@ -0,0 +1,2 @@
Python 2: safely format warning message about passing unicode strings to ``warnings.warn``, which may cause
surprising ``MemoryError`` exception when monkey patching ``warnings.warn`` itself.
Copy link
Member

Choose a reason for hiding this comment

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

(comment for my own education about pytest's documentation)

In Hypothesis we have the intersphinx_mapping configured so that we can write these as:

surprising :class:`python:MemoryError` exception when monkey 
patching :func:`python:warnings.warn` itself.

It allows for somewhat nicer formatting, but more importantly adds a hyperlink - and can check that the link target exists, which caught dozens of typos in our docs.

Has pytest decided not to do this, or just not considered it? It can be fiddly at times but also pretty useful.

Copy link
Member

Choose a reason for hiding this comment

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

i don't recall use taking a deeper look into this so it may be worth trying it - ideally someone with experience setting it up

Copy link
Member

Choose a reason for hiding this comment

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

I'll write up an issue then 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

@Zac-HD thanks a lot for the pointer, actually or intersphinx_mapping is already configured. I tested locally your changes and they actually do work. 😁

We should remember to use those sphinx references more often. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm actually I spoke too soon. While it generates the proper docs, our linter complains:

ERROR changelog/3691.bugfix.rst:1 Unknown interpreted text role "func".
ERROR changelog/3691.bugfix.rst:1 Unknown interpreted text role "class".
ERROR changelog/3691.bugfix.rst:1 Unknown interpreted text role "func".
ERROR changelog/4192.bugfix.rst:1 Unknown interpreted text role "func".
ERROR changelog/4192.bugfix.rst:1 Unknown interpreted text role "func".

@nicoddemus nicoddemus merged commit 2abd005 into pytest-dev:master Oct 19, 2018
@nicoddemus nicoddemus deleted the issue-3691 branch October 19, 2018 10:18
@@ -123,7 +123,7 @@ def warning_record_to_str(warning_message):
if unicode_warning:
warnings.warn(
"Warning is using unicode non convertible to ascii, "
"converting to a safe representation:\n %s" % msg,
"converting to a safe representation:\n {!r}".format(compat.safe_str(msg)),
Copy link
Member

Choose a reason for hiding this comment

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

oh, when I suggested {!r}, then you don't need safe_str at all I think

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh. Hmm well not sure if this will be a problem as is.

Copy link
Member

Choose a reason for hiding this comment

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

No problem, just I was hoping to eventually remove safe_str usages 🤷‍♂️

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.

4 participants