From 0a8b27ff4935fc727f1b858a8df5d3696cb9c326 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 19 Nov 2013 23:22:27 +0100 Subject: [PATCH 1/5] 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. --- CHANGELOG | 4 ++++ _pytest/main.py | 7 ------- _pytest/python.py | 11 ++++++++++- testing/python/integration.py | 37 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d859cad21..985681a1b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ Unreleased ----------------------------------- +- 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 trial to handle it on its own diff --git a/_pytest/main.py b/_pytest/main.py index 372a8019d..48084bab9 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -697,11 +697,4 @@ class Session(FSCollector): 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 --git a/_pytest/python.py b/_pytest/python.py index c09fc6f36..d10100a99 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -3,7 +3,6 @@ import py 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 @@ NoneType = type(None) 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 --git a/testing/python/integration.py b/testing/python/integration.py index 00e70df83..60002b83f 100644 --- 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 @@ class TestOEJSKITSpecials: 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 @@ class TestMockDecoration: 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): From 9eff939b023673ed6a1d5306effda7d4db85c459 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 20 Nov 2013 15:46:23 +0100 Subject: [PATCH 2/5] remove testing of xdist+genscript -- doesn't really make sense because for installing pytest-xdist you need pytest installed which defeats the purpose of genscript. --- testing/test_genscript.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/testing/test_genscript.py b/testing/test_genscript.py index eb2e634b5..f790d546a 100644 --- a/testing/test_genscript.py +++ b/testing/test_genscript.py @@ -35,14 +35,3 @@ def test_gen(testdir, anypython, standalone): 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*", - ]) From 6d1b7e94d14a3826e254cd607de7d1808d103fec Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 20 Nov 2013 16:03:55 +0100 Subject: [PATCH 3/5] add py33-xdist to tox testing --- tox.ini | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2719a9b70..9ec5b9a83 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [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-nobyte,py32,py33,py27-xdist,py33-xdist,trial [testenv] changedir=testing @@ -33,6 +33,14 @@ commands= 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-nobyte] changedir=. basepython=python2.7 From bd8a2cc18c1898673665023556e73134e78e4d75 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 20 Nov 2013 20:00:59 +0100 Subject: [PATCH 4/5] removing pexpect from general dependencies because it doesn't install on windows anymore. Instead to specific configurations for pexpect on py27 and py33 which only call the tests that need it. --- tox.ini | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 9ec5b9a83..e676b71b7 100644 --- 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,py33-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] @@ -41,6 +40,20 @@ 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 @@ -55,7 +68,6 @@ commands= [testenv:trial] changedir=. deps=twisted - pexpect commands= py.test -rsxf \ --junitxml={envlogdir}/junit-{envname}.xml {posargs:testing/test_unittest.py} From 73f36fc8b76e24d6ea09700cd72dd7a309aae6fa Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 20 Nov 2013 21:04:19 +0100 Subject: [PATCH 5/5] fix issue221 - handle importing of namespace-package with no __init__.py properly. (This is a commit after the fix -- the original issue steps for failure cannot be reproduced anymore). --- CHANGELOG | 3 +++ extra/get_issues.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 985681a1b..57177219b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -56,6 +56,9 @@ Unreleased 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 ----------------------------------- diff --git a/extra/get_issues.py b/extra/get_issues.py index 5e6ab9a68..6045d49c7 100644 --- a/extra/get_issues.py +++ b/extra/get_issues.py @@ -66,7 +66,8 @@ def report(issues): 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()