4 new commits in pytest: https://bitbucket.org/hpk42/pytest/commits/aeb2f224d691/ Changeset: aeb2f224d691 User: flub Date: 2013-11-19 18:26:18 Summary: Ensure all finalizations are run when one fails
Fixes issue287. Affected #: 3 files diff -r 282e0cca851c58e64ddaeeb56907f4376927ac13 -r aeb2f224d69130ef99a4412bd4b1c64b66561420 CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ Unreleased ----------------------------------- +- fix issue287 by running all finalizers but saving the exception + from the last failing finalizer and re-raising it so teardown will + still have failed. + - fix issue384 by removing the trial support code since the unittest compat enhancements allow trial to handle it on its own diff -r 282e0cca851c58e64ddaeeb56907f4376927ac13 -r aeb2f224d69130ef99a4412bd4b1c64b66561420 _pytest/runner.py --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -328,9 +328,17 @@ def _callfinalizers(self, colitem): finalizers = self._finalizers.pop(colitem, None) + exc = None while finalizers: fin = finalizers.pop() - fin() + try: + fin() + except KeyboardInterrupt: + raise + except: + exc = py.std.sys.exc_info() + if exc: + py.builtin._reraise(*exc) def _teardown_with_finalization(self, colitem): self._callfinalizers(colitem) diff -r 282e0cca851c58e64ddaeeb56907f4376927ac13 -r aeb2f224d69130ef99a4412bd4b1c64b66561420 testing/test_runner.py --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -43,6 +43,21 @@ pytest.raises(ValueError, lambda: ss.prepare(item)) pytest.raises(ValueError, lambda: ss.prepare(item)) + def test_teardown_multiple_one_fails(self, testdir): + r = [] + def fin1(): r.append('fin1') + def fin2(): raise Exception('oops') + def fin3(): r.append('fin3') + item = testdir.getitem("def test_func(): pass") + ss = runner.SetupState() + ss.addfinalizer(fin1, item) + ss.addfinalizer(fin2, item) + ss.addfinalizer(fin3, item) + with pytest.raises(Exception) as err: + ss._callfinalizers(item) + assert err.value.args == ('oops',) + assert r == ['fin3', 'fin1'] + class BaseFunctionalTests: def test_passfunction(self, testdir): https://bitbucket.org/hpk42/pytest/commits/20285c639280/ Changeset: 20285c639280 User: flub Date: 2013-11-21 02:15:24 Summary: Re-raise the first exception instead of the last This will make more sense if multiple fixtures depend on each other. It would be better if all exceptions could be shown however. Also depend on python 2.5+ exception hierarchy and use sys module directly. Affected #: 2 files diff -r aeb2f224d69130ef99a4412bd4b1c64b66561420 -r 20285c639280ff58255ade382b7648725fa637b0 _pytest/runner.py --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -333,10 +333,11 @@ fin = finalizers.pop() try: fin() - except KeyboardInterrupt: - raise - except: - exc = py.std.sys.exc_info() + except Exception: + # XXX Only first exception will be seen by user, + # ideally all should be reported. + if not exc: + exc = sys.exc_info() if exc: py.builtin._reraise(*exc) diff -r aeb2f224d69130ef99a4412bd4b1c64b66561420 -r 20285c639280ff58255ade382b7648725fa637b0 testing/test_runner.py --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -58,6 +58,19 @@ assert err.value.args == ('oops',) assert r == ['fin3', 'fin1'] + def test_teardown_multiple_fail(self, testdir): + # Ensure the first exception is the one which is re-raised. + # Ideally both would be reported however. + def fin1(): raise Exception('oops1') + def fin2(): raise Exception('oops2') + item = testdir.getitem("def test_func(): pass") + ss = runner.SetupState() + ss.addfinalizer(fin1, item) + ss.addfinalizer(fin2, item) + with pytest.raises(Exception) as err: + ss._callfinalizers(item) + assert err.value.args == ('oops2',) + class BaseFunctionalTests: def test_passfunction(self, testdir): https://bitbucket.org/hpk42/pytest/commits/d1087fb4853f/ Changeset: d1087fb4853f User: flub Date: 2013-11-21 02:16:49 Summary: Merge Affected #: 7 files diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ - fix issue287 by running all finalizers but saving the exception from the last failing finalizer and re-raising it so teardown will still have failed. +- fix ordering when mock.patch or other standard decorator-wrappings + are used with test methods. This fixues issue346. Thanks to + Ronny Pfannschmidt and Donald Stufft for helping to isolate it. - fix issue384 by removing the trial support code since the unittest compat enhancements allow diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f _pytest/main.py --- a/_pytest/main.py +++ b/_pytest/main.py @@ -697,11 +697,4 @@ yield x node.ihook.pytest_collectreport(report=rep) -def getfslineno(obj): - # xxx let decorators etc specify a sane ordering - if hasattr(obj, 'place_as'): - obj = obj.place_as - fslineno = py.code.getfslineno(obj) - assert isinstance(fslineno[1], int), obj - return fslineno diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -3,7 +3,6 @@ import inspect import sys import pytest -from _pytest.main import getfslineno from _pytest.mark import MarkDecorator from _pytest.monkeypatch import monkeypatch from py._code.code import TerminalRepr @@ -15,6 +14,16 @@ callable = py.builtin.callable +def getfslineno(obj): + # xxx let decorators etc specify a sane ordering + while hasattr(obj, "__wrapped__"): + obj = obj.__wrapped__ + if hasattr(obj, 'place_as'): + obj = obj.place_as + fslineno = py.code.getfslineno(obj) + assert isinstance(fslineno[1], int), obj + return fslineno + def getimfunc(func): try: return func.__func__ diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f extra/get_issues.py --- a/extra/get_issues.py +++ b/extra/get_issues.py @@ -66,7 +66,8 @@ if __name__ == "__main__": import argparse parser = argparse.ArgumentParser("process bitbucket issues") - parser.add_argument("--refresh", help="invalidate cache, refresh issues") + parser.add_argument("--refresh", action="store_true", + help="invalidate cache, refresh issues") parser.add_argument("--cache", action="store", default="issues.json", help="cache file") args = parser.parse_args() diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f testing/python/integration.py --- a/testing/python/integration.py +++ b/testing/python/integration.py @@ -1,5 +1,6 @@ import pytest from _pytest import runner +from _pytest import python class TestOEJSKITSpecials: def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage @@ -55,6 +56,20 @@ assert not clscol.funcargs +def test_wrapped_getfslineno(): + def func(): + pass + def wrap(f): + func.__wrapped__ = f + func.patchings = ["qwe"] + return func + @wrap + def wrapped_func(x, y, z): + pass + fs, lineno = python.getfslineno(wrapped_func) + fs2, lineno2 = python.getfslineno(wrap) + assert lineno > lineno2, "getfslineno does not unwrap correctly" + class TestMockDecoration: def test_wrapped_getfuncargnames(self): from _pytest.python import getfuncargnames @@ -119,6 +134,28 @@ reprec = testdir.inline_run() reprec.assertoutcome(passed=2) + def test_mock_sorting(self, testdir): + pytest.importorskip("mock", "1.0.1") + testdir.makepyfile(""" + import os + import mock + + @mock.patch("os.path.abspath") + def test_one(abspath): + pass + @mock.patch("os.path.abspath") + def test_two(abspath): + pass + @mock.patch("os.path.abspath") + def test_three(abspath): + pass + """) + reprec = testdir.inline_run() + calls = reprec.getreports("pytest_runtest_logreport") + calls = [x for x in calls if x.when == "call"] + names = [x.nodeid.split("::")[-1] for x in calls] + assert names == ["test_one", "test_two", "test_three"] + class TestReRunTests: def test_rerun(self, testdir): diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f testing/test_genscript.py --- a/testing/test_genscript.py +++ b/testing/test_genscript.py @@ -35,14 +35,3 @@ result = standalone.run(anypython, testdir, p) assert result.ret != 0 -def test_rundist(testdir, pytestconfig, standalone): - pytestconfig.pluginmanager.skipifmissing("xdist") - testdir.makepyfile(""" - def test_one(): - pass - """) - result = standalone.run(sys.executable, testdir, '-n', '3') - assert result.ret == 0 - result.stdout.fnmatch_lines([ - "*1 passed*", - ]) diff -r 20285c639280ff58255ade382b7648725fa637b0 -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f tox.ini --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,11 @@ [tox] distshare={homedir}/.tox/distshare -envlist=flakes,py25,py26,py27,pypy,py27-nobyte,py32,py33,py27-xdist,trial +envlist=flakes,py25,py26,py27,pypy,py27-pexpect,py33-pexpect,py27-nobyte,py32,py33,py27-xdist,py33-xdist,trial [testenv] changedir=testing commands= py.test --lsof -rfsxX --junitxml={envlogdir}/junit-{envname}.xml [] deps= - pexpect nose [testenv:genscript] @@ -33,6 +32,28 @@ py.test -n3 -rfsxX \ --junitxml={envlogdir}/junit-{envname}.xml testing +[testenv:py33-xdist] +changedir=. +basepython=python3.3 +deps={[testenv:py27-xdist]deps} +commands= + py.test -n3 -rfsxX \ + --junitxml={envlogdir}/junit-{envname}.xml testing + +[testenv:py27-pexpect] +changedir=testing +basepython=python2.7 +deps=pexpect +commands= + py.test -rfsxX test_pdb.py test_terminal.py test_unittest.py + +[testenv:py33-pexpect] +changedir=testing +basepython=python2.7 +deps={[testenv:py27-pexpect]deps} +commands= + py.test -rfsxX test_pdb.py test_terminal.py test_unittest.py + [testenv:py27-nobyte] changedir=. basepython=python2.7 @@ -47,7 +68,6 @@ [testenv:trial] changedir=. deps=twisted - pexpect commands= py.test -rsxf \ --junitxml={envlogdir}/junit-{envname}.xml {posargs:testing/test_unittest.py} https://bitbucket.org/hpk42/pytest/commits/6333d041d8dd/ Changeset: 6333d041d8dd User: flub Date: 2013-11-21 02:37:48 Summary: Fixup changelog This seems to have gone wrong in the merge. Affected #: 1 file diff -r d1087fb4853fe5bb65bb1f215cf88ee188467a4f -r 6333d041d8dd3ba39e2ca32e07d2354c8525cfdf CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - fix issue287 by running all finalizers but saving the exception from the last failing finalizer and re-raising it so teardown will still have failed. + - fix ordering when mock.patch or other standard decorator-wrappings are used with test methods. This fixues issue346. Thanks to Ronny Pfannschmidt and Donald Stufft for helping to isolate it. @@ -59,6 +60,9 @@ although it's not needed by pytest itself atm. Also fix caching. Fixes issue376. +- fix issue221 - handle importing of namespace-package with no + __init__.py properly. + Changes between 2.4.1 and 2.4.2 ----------------------------------- 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. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit