-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1610 from Zac-HD/warning-stacklevel
Fix deprecation warning stacklevel
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RELEASE_TYPE: patch | ||
|
||
This patch ensures that Hypothesis deprecation warnings display the code | ||
that emitted them when you're not running in ``-Werror`` mode (:issue:`652`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# coding=utf-8 | ||
# | ||
# This file is part of Hypothesis, which may be found at | ||
# https://github.com/HypothesisWorks/hypothesis-python | ||
# | ||
# Most of this work is copyright (C) 2013-2018 David R. MacIver | ||
# ([email protected]), but it contains contributions by others. See | ||
# CONTRIBUTING.rst for a full list of people who may hold copyright, and | ||
# consult the git log if you need to determine who owns an individual | ||
# contribution. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# END HEADER | ||
|
||
from __future__ import division, print_function, absolute_import | ||
|
||
import warnings | ||
|
||
from hypothesis.errors import HypothesisDeprecationWarning | ||
from hypothesis._settings import note_deprecation | ||
from hypothesis.strategies import integers, composite | ||
|
||
|
||
def test_note_deprecation_blames_right_code_issue_652(): | ||
msg = 'this is an arbitrary deprecation warning message' | ||
|
||
@composite | ||
def deprecated_strategy(draw): | ||
draw(integers()) | ||
note_deprecation(msg) | ||
|
||
with warnings.catch_warnings(record=True) as log: | ||
warnings.simplefilter('always') | ||
deprecated_strategy().example() | ||
|
||
assert len(log) == 1 | ||
record, = log | ||
# We got the warning we expected, from the right file | ||
assert isinstance(record.message, HypothesisDeprecationWarning) | ||
assert record.message.args == (msg,) | ||
assert record.filename == __file__ |