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
This commit is contained in:
holger krekel 2012-10-22 16:12:22 +02:00
parent f28f073c7c
commit 05c86aeb28
6 changed files with 40 additions and 13 deletions

View File

@ -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
-----------------------------------

View File

@ -1,2 +1,2 @@
#
__version__ = '2.3.2.dev6'
__version__ = '2.3.2.dev7'

View File

@ -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. """

View File

@ -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)

View File

@ -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'],

View File

@ -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