Merge pull request #2235 from bluetech/dont-execute-properties
ignore property errors when parsing fixure factories
This commit is contained in:
commit
a4fb971c1f
1
AUTHORS
1
AUTHORS
|
@ -118,6 +118,7 @@ Piotr Banaszkiewicz
|
||||||
Punyashloka Biswal
|
Punyashloka Biswal
|
||||||
Quentin Pradet
|
Quentin Pradet
|
||||||
Ralf Schmitt
|
Ralf Schmitt
|
||||||
|
Ran Benita
|
||||||
Raphael Pierzina
|
Raphael Pierzina
|
||||||
Raquel Alegre
|
Raquel Alegre
|
||||||
Roberto Polli
|
Roberto Polli
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
* Ignore exceptions raised from descriptors (e.g. properties) during Python test collection (`#2234`_).
|
||||||
|
Thanks to `@bluetech`_.
|
||||||
|
|
||||||
* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
|
* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
|
||||||
Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.
|
Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.
|
||||||
|
|
||||||
|
@ -16,6 +19,10 @@
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
.. _#2234: https://github.com/pytest-dev/pytest/issues/2234
|
||||||
|
|
||||||
|
.. _@bluetech: https://github.com/bluetech
|
||||||
|
|
||||||
.. _#2160: https://github.com/pytest-dev/pytest/issues/2160
|
.. _#2160: https://github.com/pytest-dev/pytest/issues/2160
|
||||||
|
|
||||||
.. _PEP-479: https://www.python.org/dev/peps/pep-0479/
|
.. _PEP-479: https://www.python.org/dev/peps/pep-0479/
|
||||||
|
|
|
@ -14,6 +14,7 @@ from _pytest.compat import (
|
||||||
getfslineno, get_real_func,
|
getfslineno, get_real_func,
|
||||||
is_generator, isclass, getimfunc,
|
is_generator, isclass, getimfunc,
|
||||||
getlocation, getfuncargnames,
|
getlocation, getfuncargnames,
|
||||||
|
safe_getattr,
|
||||||
)
|
)
|
||||||
|
|
||||||
def pytest_sessionstart(session):
|
def pytest_sessionstart(session):
|
||||||
|
@ -124,8 +125,6 @@ def getfixturemarker(obj):
|
||||||
exceptions."""
|
exceptions."""
|
||||||
try:
|
try:
|
||||||
return getattr(obj, "_pytestfixturefunction", None)
|
return getattr(obj, "_pytestfixturefunction", None)
|
||||||
except KeyboardInterrupt:
|
|
||||||
raise
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# some objects raise errors like request (from flask import request)
|
# some objects raise errors like request (from flask import request)
|
||||||
# we don't expect them to be fixture functions
|
# we don't expect them to be fixture functions
|
||||||
|
@ -1068,7 +1067,9 @@ class FixtureManager:
|
||||||
self._holderobjseen.add(holderobj)
|
self._holderobjseen.add(holderobj)
|
||||||
autousenames = []
|
autousenames = []
|
||||||
for name in dir(holderobj):
|
for name in dir(holderobj):
|
||||||
obj = getattr(holderobj, name, None)
|
# The attribute can be an arbitrary descriptor, so the attribute
|
||||||
|
# access below can raise. safe_getatt() ignores such exceptions.
|
||||||
|
obj = safe_getattr(holderobj, name, None)
|
||||||
# fixture functions have a pytest_funcarg__ prefix (pre-2.3 style)
|
# fixture functions have a pytest_funcarg__ prefix (pre-2.3 style)
|
||||||
# or are "@pytest.fixture" marked
|
# or are "@pytest.fixture" marked
|
||||||
marker = getfixturemarker(obj)
|
marker = getfixturemarker(obj)
|
||||||
|
|
|
@ -166,6 +166,16 @@ class TestClass:
|
||||||
"because it has a __new__ constructor*"
|
"because it has a __new__ constructor*"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_issue2234_property(self, testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
class TestCase(object):
|
||||||
|
@property
|
||||||
|
def prop(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest()
|
||||||
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
||||||
|
|
||||||
|
|
||||||
class TestGenerator:
|
class TestGenerator:
|
||||||
def test_generative_functions(self, testdir):
|
def test_generative_functions(self, testdir):
|
||||||
|
|
Loading…
Reference in New Issue