From 05c86aeb28fefad9648cdb7af75b4dc95ac1a0a7 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 22 Oct 2012 16:12:22 +0200 Subject: [PATCH] make sure ihook uses a node's fspath - important for hooks e.g. during a Module's collect to pick up conftest.py files residing in the same dir --- CHANGELOG | 18 ++++++++++-------- _pytest/__init__.py | 2 +- _pytest/main.py | 8 +++++--- _pytest/python.py | 1 + setup.py | 2 +- testing/test_python.py | 22 ++++++++++++++++++++++ 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 675d95a8e..b7e93862a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,20 +2,22 @@ Changes between 2.3.1 and 2.3.2.dev ----------------------------------- - fix issue205 - conftests in subdirs customizing - pytest_pycollect_makemodule now work properly + pytest_pycollect_makemodule and pytest_pycollect_makeitem + now work properly - fix teardown-ordering for parametrized setups -- fix exception message check of test_nose.py to pass on python33 as well +- "python setup.py test" now works with pytest itself -- fix issue206 - fix test_assertrewrite.py to work when a global - PYTHONDONTWRITEBYTECODE=1 is present +- fix/improve internal/packaging related bits: -- add tox.ini to pytest distribution so that ignore-dirs and others config - bits are properly distributed for maintainers who run pytest-own tests + - exception message check of test_nose.py now passes on python33 as well -- add some logic to setup.py such that "python setup.py test" works with - pytest itself + - issue206 - fix test_assertrewrite.py to work when a global + PYTHONDONTWRITEBYTECODE=1 is present + + - add tox.ini to pytest distribution so that ignore-dirs and others config + bits are properly distributed for maintainers who run pytest-own tests Changes between 2.3.0 and 2.3.1 ----------------------------------- diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 74fe8cc06..4bbc15d32 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.2.dev6' +__version__ = '2.3.2.dev7' diff --git a/_pytest/main.py b/_pytest/main.py index 4f310d756..6063c230f 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -211,14 +211,16 @@ class Node(object): #: filesystem path where this node was collected from (can be None) self.fspath = getattr(parent, 'fspath', None) - #: fspath sensitive hook proxy used to call pytest hooks - self.ihook = self.session.gethookproxy(self.fspath) - #: keywords/markers collected from all scopes self.keywords = NodeKeywords(self) #self.extrainit() + @property + def ihook(self): + """ fspath sensitive hook proxy used to call pytest hooks""" + return self.session.gethookproxy(self.fspath) + #def extrainit(self): # """"extra initialization after Node is initialized. Implemented # by some subclasses. """ diff --git a/_pytest/python.py b/_pytest/python.py index aaeaa17ee..cad2d37ef 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -288,6 +288,7 @@ class PyCollector(PyobjMixin, pytest.Collector): return l def makeitem(self, name, obj): + #assert self.ihook.fspath == self.fspath, self return self.ihook.pytest_pycollect_makeitem( collector=self, name=name, obj=obj) diff --git a/setup.py b/setup.py index 4610fca47..6478c0391 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.3.2.dev6', + version='2.3.2.dev7', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_python.py b/testing/test_python.py index 7d4527ecb..78b5484c0 100644 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -419,6 +419,28 @@ class TestConftestCustomization: reprec = testdir.inline_run() reprec.assertoutcome(passed=1) + def test_customized_pymakeitem(self, testdir): + b = testdir.mkdir("a").mkdir("b") + b.join("conftest.py").write(py.code.Source(""" + def pytest_pycollect_makeitem(__multicall__): + result = __multicall__.execute() + if result: + for func in result: + func._some123 = "world" + return result + """)) + b.join("test_module.py").write(py.code.Source(""" + import pytest + + @pytest.fixture() + def obj(request): + return request.node._some123 + def test_hello(obj): + assert obj == "world" + """)) + reprec = testdir.inline_run() + reprec.assertoutcome(passed=1) + def test_pytest_pycollect_makeitem(self, testdir): testdir.makeconftest(""" import pytest