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

Fix deprecation warning stacklevel #1610

Merged
merged 1 commit into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
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`).
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def note_deprecation(message, s=None):
verbosity = s.verbosity
warning = HypothesisDeprecationWarning(message)
if verbosity > Verbosity.quiet:
warnings.warn(warning, stacklevel=3)
warnings.warn(warning, stacklevel=2)


settings.register_profile('default', settings())
Expand Down
44 changes: 44 additions & 0 deletions hypothesis-python/tests/nocover/test_regressions.py
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__