From d8fcc96563869a4b700de1f535a80a802c02f227 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 2 Aug 2010 16:39:36 +0200 Subject: [PATCH] committed a xfailing test for sibling conftests --HG-- branch : trunk --- testing/test_collect.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/testing/test_collect.py b/testing/test_collect.py index 300c1ad62..43e611f53 100644 --- a/testing/test_collect.py +++ b/testing/test_collect.py @@ -266,6 +266,35 @@ class TestRootCol: col2 = config._rootcol.fromtrail(trail) assert col2 == col + @py.test.mark.xfail(reason="http://bitbucket.org/hpk42/py-trunk/issue/109") + def test_sibling_conftest_issue109(self, testdir): + """ + This test is to make sure that the conftest.py of sibling directories is not loaded + if py.test is run for/in one of the siblings directory and those sibling directories + are not packaged together with an __init__.py. See bitbucket issue #109. + """ + for dirname in ['a', 'b']: + testdir.tmpdir.ensure(dirname, dir=True) + testdir.tmpdir.ensure(dirname, '__init__.py') + + # To create the conftest.py I would like to use testdir.make*-methods + # but as far as I have seen they can only create files in testdir.tempdir + # Maybe there is a way to explicitly specifiy the directory on which those + # methods work or a completely better way to do that? + backupTmpDir = testdir.tmpdir + testdir.tmpdir = testdir.tmpdir.join(dirname) + testdir.makeconftest(""" + _DIR_NAME = '%s' + def pytest_configure(config): + if config.args and config.args[0] != _DIR_NAME: + raise Exception("py.test run for '" + config.args[0] + "', but '" + _DIR_NAME + "/conftest.py' loaded.") + """ % dirname) + testdir.tmpdir = backupTmpDir + + for dirname, other_dirname in [('a', 'b'), ('b', 'a')]: + result = testdir.runpytest(dirname) + assert result.ret == 0, "test_sibling_conftest: py.test run for '%s', but '%s/conftest.py' loaded." % (dirname, other_dirname) + def test_totrail_topdir_and_beyond(self, testdir, tmpdir): config = testdir.reparseconfig() col = config.getnode(config.topdir)