3 new commits in pytest:
https://bitbucket.org/hpk42/pytest/changeset/c52af7d3cfb5/ changeset: c52af7d3cfb5 user: hpk42 date: 2012-10-28 17:40:30 summary: remove issue that doesn't make sense anymore affected #: 1 file diff -r 678655781ea359b14d96829c205322db47018239 -r c52af7d3cfb50cd43f7907bd39fe3227960c64fe ISSUES.txt --- a/ISSUES.txt +++ b/ISSUES.txt @@ -48,59 +48,6 @@ not sufficient to always allow non-matches? -unify item/request classes, generalize items ---------------------------------------------------------------- -tags: 2.4 wish - -in lieu of extended parametrization and the new way to specify resource -factories in terms of the parametrize decorator, consider unification -of the item and request class. This also is connected with allowing -funcargs in setup functions. Example of new item API: - - item.getresource("db") # alias for request.getfuncargvalue - item.addfinalizer(...) - item.cached_setup(...) - item.applymarker(...) - -test classes/modules could then use this api via:: - - def pytest_runtest_setup(item): - use item API ... - -introduction of this new method needs to be _fully_ backward compatible - -and the documentation needs to change along to mention this new way of -doing things. - -impl note: probably Request._fillfixtures would be called from the -python plugins own pytest_runtest_setup(item) and would call -item.getresource(X) for all X in the funcargs of a function. - -XXX is it possible to even put the above item API to Nodes, i.e. also -to Directorty/module/file/class collectors? Problem is that current -funcarg factories presume they are called with a per-function (even -per-funcarg-per-function) scope. Could there be small tweaks to the new -API that lift this restriction? - -consider:: - - def setup_class(cls, tmpdir): - # would get a per-class tmpdir because tmpdir parametrization - # would know that it is called with a class scope - # - # - # -this looks very difficult because those setup functions are also used -by nose etc. Rather consider introduction of a new setup hook: - - def setup_test(self, item): - self.db = item.cached_setup(..., scope='class') - self.tmpdir = item.getresource("tmpdir") - -this should be compatible to unittest/nose and provide much of what -"testresources" provide. XXX This would not allow full parametrization -such that test function could be run multiple times with different -values. See "parametrized attributes" issue. - allow parametrized attributes on classes -------------------------------------------------- https://bitbucket.org/hpk42/pytest/changeset/9a0bff73c95e/ changeset: 9a0bff73c95e user: hpk42 date: 2012-10-31 17:01:24 summary: merge affected #: 3 files diff -r c52af7d3cfb50cd43f7907bd39fe3227960c64fe -r 9a0bff73c95e37a9752936e9eed791e6770acbae CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ Changes between 2.3.2 and 2.3.3.dev ----------------------------------- +- fix issue 214: gracefully handle proxy objects that + look like fixtures but raise exceptions on introspection - fix issue213 - allow to parametrize with values like numpy arrays that do not support an __eq__ operator diff -r c52af7d3cfb50cd43f7907bd39fe3227960c64fe -r 9a0bff73c95e37a9752936e9eed791e6770acbae _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1551,7 +1551,15 @@ continue # fixture functions have a pytest_funcarg__ prefix (pre-2.3 style) # or are "@pytest.fixture" marked - marker = getattr(obj, "_pytestfixturefunction", None) + try: + marker = getattr(obj, "_pytestfixturefunction", None) + except RuntimeError: + # some proxy objects raise RuntimeError + # flasks request globals are one example + # those aren't fixture functions, so we can ignore + # XXX: maybe trace it when it happens? + marker = None + if marker is None: if not name.startswith(self._argprefix): continue diff -r c52af7d3cfb50cd43f7907bd39fe3227960c64fe -r 9a0bff73c95e37a9752936e9eed791e6770acbae testing/test_python.py --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1611,6 +1611,34 @@ ]) assert "INTERNAL" not in result.stdout.str() + +def test_funcarg_fixture_discovery_failure_issue214(testdir): + # some proxy objects raise RuntimeError on getattr + # for example flask.request + p = testdir.makepyfile(""" + + class EvilObject(object): + def __call__(self): + #needed to trick discovery + pass + def __getattr__(self, arg): + raise RuntimeError('uhm ' + arg) + + + fixture = EvilObject() + + def test_1(): + pass + """) + result = testdir.runpytest('--fulltrace') + result.stdout.fnmatch_lines([ + '*1 passed*' + ]) + assert "INTERNAL" not in result.stdout.str() + assert "ERROR" not in result.stdout.str() + + + class TestReportInfo: def test_itemreport_reportinfo(self, testdir, linecomp): testdir.makeconftest(""" https://bitbucket.org/hpk42/pytest/changeset/a751a14ccfb3/ changeset: a751a14ccfb3 user: hpk42 date: 2012-10-31 17:00:55 summary: extended - fix issue214 - ignore attribute-access errors with objects in test modules that can blow up (for example flask's request object) affected #: 6 files diff -r 9a0bff73c95e37a9752936e9eed791e6770acbae -r a751a14ccfb360f4f72ab138d5a9647e89213a82 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,12 @@ Changes between 2.3.2 and 2.3.3.dev ----------------------------------- -- fix issue 214: gracefully handle proxy objects that - look like fixtures but raise exceptions on introspection +- fix issue214 - parse modules that contain special objects like e. g. + flask's request object which blows up on getattr access if no request + is active. - fix issue213 - allow to parametrize with values like numpy arrays that - do not support an __eq__ operator + do not support an __eq__ operator + Changes between 2.3.1 and 2.3.2 ----------------------------------- diff -r 9a0bff73c95e37a9752936e9eed791e6770acbae -r a751a14ccfb360f4f72ab138d5a9647e89213a82 _pytest/__init__.py --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.2' +__version__ = '2.3.3.dev1' diff -r 9a0bff73c95e37a9752936e9eed791e6770acbae -r a751a14ccfb360f4f72ab138d5a9647e89213a82 _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1552,12 +1552,12 @@ # fixture functions have a pytest_funcarg__ prefix (pre-2.3 style) # or are "@pytest.fixture" marked try: - marker = getattr(obj, "_pytestfixturefunction", None) - except RuntimeError: - # some proxy objects raise RuntimeError - # flasks request globals are one example - # those aren't fixture functions, so we can ignore - # XXX: maybe trace it when it happens? + marker = obj._pytestfixturefunction + except KeyboardInterrupt: + raise + except Exception: + # some objects raise errors like request (from flask import request) + # we don't expect them to be fixture functions marker = None if marker is None: diff -r 9a0bff73c95e37a9752936e9eed791e6770acbae -r a751a14ccfb360f4f72ab138d5a9647e89213a82 doc/en/example/nonpython/conftest.py --- a/doc/en/example/nonpython/conftest.py +++ b/doc/en/example/nonpython/conftest.py @@ -2,10 +2,10 @@ import pytest -def pytest_collect_file(path, parent): +def pytest_collect_file(parent, path): if path.ext == ".yml" and path.basename.startswith("test"): return YamlFile(path, parent) - + class YamlFile(pytest.File): def collect(self): import yaml # we need a yaml parser, e.g. PyYAML @@ -17,7 +17,7 @@ def __init__(self, name, parent, spec): super(YamlItem, self).__init__(name, parent) self.spec = spec - + def runtest(self): for name, value in self.spec.items(): # some custom test execution (dumb example follows) diff -r 9a0bff73c95e37a9752936e9eed791e6770acbae -r a751a14ccfb360f4f72ab138d5a9647e89213a82 setup.py --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.3.2', + version='2.3.3.dev1', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff -r 9a0bff73c95e37a9752936e9eed791e6770acbae -r a751a14ccfb360f4f72ab138d5a9647e89213a82 testing/test_python.py --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1612,33 +1612,6 @@ assert "INTERNAL" not in result.stdout.str() -def test_funcarg_fixture_discovery_failure_issue214(testdir): - # some proxy objects raise RuntimeError on getattr - # for example flask.request - p = testdir.makepyfile(""" - - class EvilObject(object): - def __call__(self): - #needed to trick discovery - pass - def __getattr__(self, arg): - raise RuntimeError('uhm ' + arg) - - - fixture = EvilObject() - - def test_1(): - pass - """) - result = testdir.runpytest('--fulltrace') - result.stdout.fnmatch_lines([ - '*1 passed*' - ]) - assert "INTERNAL" not in result.stdout.str() - assert "ERROR" not in result.stdout.str() - - - class TestReportInfo: def test_itemreport_reportinfo(self, testdir, linecomp): testdir.makeconftest(""" @@ -2145,6 +2118,20 @@ """) return testdir + def test_parsefactories_evil_objects_issue214(self, testdir): + testdir.makepyfile(""" + class A: + def __call__(self): + pass + def __getattr__(self, name): + raise RuntimeError() + a = A() + def test_hello(): + pass + """) + reprec = testdir.inline_run() + reprec.assertoutcome(passed=1, failed=0) + def test_parsefactories_conftest(self, testdir): testdir.makepyfile(""" def test_hello(item, fm): Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn