Make sure warnings are not shown if a property is executed, fixes #1383

This commit is contained in:
Dave Halter
2019-12-13 01:48:45 +01:00
parent 5e3e268cc6
commit 769b3556d2
2 changed files with 21 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
Tests of ``jedi.api.Interpreter``.
"""
import sys
import warnings
import pytest
@@ -197,6 +198,20 @@ def test_getitem_side_effects():
_assert_interpreter_complete('foo["asdf"].upper', locals(), ['upper'])
@pytest.mark.parametrize('stacklevel', [1, 2])
@pytest.mark.filterwarnings("error")
def test_property_warnings(stacklevel):
class Foo3:
@property
def prop(self):
# Possible side effects here, should therefore not call this.
warnings.warn("foo", DeprecationWarning, stacklevel=stacklevel)
return ''
foo = Foo3()
_assert_interpreter_complete('foo.prop.uppe', locals(), ['upper'])
@pytest.fixture(params=[False, True])
def allow_descriptor_access_or_not(request, monkeypatch):
monkeypatch.setattr(jedi.Interpreter, '_allow_descriptor_getattr_default', request.param)