fix issue 109 - sibling conftest.py files shall not be loaded.
also simplify / refine tests a bit. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									4eb45dab08
								
							
						
					
					
						commit
						29051458fc
					
				| 
						 | 
					@ -2,6 +2,9 @@
 | 
				
			||||||
Changes between 1.3.4 and 1.4.0.dev0
 | 
					Changes between 1.3.4 and 1.4.0.dev0
 | 
				
			||||||
==================================================
 | 
					==================================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- fix issue109 - sibling conftest.py files will not be loaded.
 | 
				
			||||||
 | 
					  (and Directory collectors cannot be customized anymore from a Directory's
 | 
				
			||||||
 | 
					  conftest.py - this needs to happen at least one level up).
 | 
				
			||||||
- introduce (customizable) assertion failure representations (Floris Bruynooghe)
 | 
					- introduce (customizable) assertion failure representations (Floris Bruynooghe)
 | 
				
			||||||
- nose-plugin: pass through type-signature failures in setup/teardown
 | 
					- nose-plugin: pass through type-signature failures in setup/teardown
 | 
				
			||||||
  functions instead of not calling them (Ed Singleton)
 | 
					  functions instead of not calling them (Ed Singleton)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,8 @@ def pytest_runtest_mainloop(session):
 | 
				
			||||||
    return True
 | 
					    return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pytest_ignore_collect(path, config):
 | 
					def pytest_ignore_collect(path, config):
 | 
				
			||||||
    ignore_paths = config.getconftest_pathlist("collect_ignore", path=path)
 | 
					    p = path.dirpath()
 | 
				
			||||||
 | 
					    ignore_paths = config.getconftest_pathlist("collect_ignore", path=p)
 | 
				
			||||||
    ignore_paths = ignore_paths or []
 | 
					    ignore_paths = ignore_paths or []
 | 
				
			||||||
    excludeopt = config.getvalue("ignore")
 | 
					    excludeopt = config.getvalue("ignore")
 | 
				
			||||||
    if excludeopt:
 | 
					    if excludeopt:
 | 
				
			||||||
| 
						 | 
					@ -34,10 +35,6 @@ def pytest_ignore_collect(path, config):
 | 
				
			||||||
    return path in ignore_paths
 | 
					    return path in ignore_paths
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pytest_collect_directory(path, parent):
 | 
					def pytest_collect_directory(path, parent):
 | 
				
			||||||
    # XXX reconsider the following comment
 | 
					 | 
				
			||||||
    # not use parent.Directory here as we generally
 | 
					 | 
				
			||||||
    # want dir/conftest.py to be able to
 | 
					 | 
				
			||||||
    # define Directory(dir) already
 | 
					 | 
				
			||||||
    if not parent.recfilter(path): # by default special ".cvs", ...
 | 
					    if not parent.recfilter(path): # by default special ".cvs", ...
 | 
				
			||||||
        # check if cmdline specified this dir or a subdir directly
 | 
					        # check if cmdline specified this dir or a subdir directly
 | 
				
			||||||
        for arg in parent.collection._argfspaths:
 | 
					        for arg in parent.collection._argfspaths:
 | 
				
			||||||
| 
						 | 
					@ -45,8 +42,7 @@ def pytest_collect_directory(path, parent):
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
    Directory = parent.config._getcollectclass('Directory', path)
 | 
					    return parent.Directory(path, parent=parent)
 | 
				
			||||||
    return Directory(path, parent=parent)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pytest_report_iteminfo(item):
 | 
					def pytest_report_iteminfo(item):
 | 
				
			||||||
    return item.reportinfo()
 | 
					    return item.reportinfo()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,8 @@ class Conftest(object):
 | 
				
			||||||
                self._path2confmods[None] = self.getconftestmodules(anchor)
 | 
					                self._path2confmods[None] = self.getconftestmodules(anchor)
 | 
				
			||||||
                # let's also consider test* dirs
 | 
					                # let's also consider test* dirs
 | 
				
			||||||
                if anchor.check(dir=1):
 | 
					                if anchor.check(dir=1):
 | 
				
			||||||
                    for x in anchor.listdir(lambda x: x.check(dir=1, dotfile=0)):
 | 
					                    for x in anchor.listdir("test*"):
 | 
				
			||||||
 | 
					                        if x.check(dir=1):
 | 
				
			||||||
                            self.getconftestmodules(x)
 | 
					                            self.getconftestmodules(x)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -163,34 +163,31 @@ class TestGeneralUsage:
 | 
				
			||||||
        result = testdir.runpython(p, prepend=False)
 | 
					        result = testdir.runpython(p, prepend=False)
 | 
				
			||||||
        assert not result.ret
 | 
					        assert not result.ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @py.test.mark.xfail(reason="http://bitbucket.org/hpk42/py-trunk/issue/109")
 | 
					    def test_issue109_sibling_conftests_not_loaded(self, testdir):
 | 
				
			||||||
    def test_sibling_conftest_issue109(self, testdir):
 | 
					        sub1 = testdir.tmpdir.mkdir("sub1")
 | 
				
			||||||
        """
 | 
					        sub2 = testdir.tmpdir.mkdir("sub2")
 | 
				
			||||||
        This test is to make sure that the conftest.py of sibling directories is not loaded
 | 
					        sub1.join("conftest.py").write("assert 0")
 | 
				
			||||||
        if py.test is run for/in one of the siblings directory and those sibling directories
 | 
					        result = testdir.runpytest(sub2)
 | 
				
			||||||
        are not packaged together with an __init__.py. See bitbucket issue #109.
 | 
					        assert result.ret == 0
 | 
				
			||||||
        """
 | 
					        sub2.ensure("__init__.py")
 | 
				
			||||||
        for dirname in ['a', 'b']:
 | 
					        p = sub2.ensure("test_hello.py")
 | 
				
			||||||
            testdir.tmpdir.ensure(dirname, dir=True)
 | 
					        result = testdir.runpytest(p)
 | 
				
			||||||
            testdir.tmpdir.ensure(dirname, '__init__.py')
 | 
					        assert result.ret == 0
 | 
				
			||||||
 | 
					        result = testdir.runpytest(sub1)
 | 
				
			||||||
 | 
					        assert result.ret != 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # To create the conftest.py I would like to use testdir.make*-methods
 | 
					    def test_directory_skipped(self, testdir):
 | 
				
			||||||
            # 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("""
 | 
					        testdir.makeconftest("""
 | 
				
			||||||
                _DIR_NAME = '%s'
 | 
					            import py
 | 
				
			||||||
                def pytest_configure(config):
 | 
					            def pytest_ignore_collect():
 | 
				
			||||||
                    if config.args and config.args[0] != _DIR_NAME:
 | 
					                py.test.skip("intentional")
 | 
				
			||||||
                        raise Exception("py.test run for '" + config.args[0] + "', but '" + _DIR_NAME + "/conftest.py' loaded.")
 | 
					        """)
 | 
				
			||||||
            """ % dirname)
 | 
					        testdir.makepyfile("def test_hello(): pass")
 | 
				
			||||||
            testdir.tmpdir = backupTmpDir
 | 
					        result = testdir.runpytest()
 | 
				
			||||||
 | 
					        assert result.ret == 0
 | 
				
			||||||
        for dirname, other_dirname in [('a', 'b'), ('b', 'a')]:
 | 
					        result.stdout.fnmatch_lines([
 | 
				
			||||||
            result = testdir.runpytest(dirname)
 | 
					            "*1 skipped*"
 | 
				
			||||||
            assert result.ret == 0, "test_sibling_conftest: py.test run for '%s', but '%s/conftest.py' loaded." % (dirname, other_dirname)
 | 
					        ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_multiple_items_per_collector_byid(self, testdir):
 | 
					    def test_multiple_items_per_collector_byid(self, testdir):
 | 
				
			||||||
        c = testdir.makeconftest("""
 | 
					        c = testdir.makeconftest("""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,7 @@ class TestConftestValueAccessGlobal:
 | 
				
			||||||
        conftest = Conftest(onimport=l.append)
 | 
					        conftest = Conftest(onimport=l.append)
 | 
				
			||||||
        conftest.setinitial([basedir.join("adir"),
 | 
					        conftest.setinitial([basedir.join("adir"),
 | 
				
			||||||
            '--confcutdir=%s' % basedir])
 | 
					            '--confcutdir=%s' % basedir])
 | 
				
			||||||
        assert len(l) == 2
 | 
					        assert len(l) == 1
 | 
				
			||||||
        assert conftest.rget("a") == 1
 | 
					        assert conftest.rget("a") == 1
 | 
				
			||||||
        assert conftest.rget("b", basedir.join("adir", "b")) == 2
 | 
					        assert conftest.rget("b", basedir.join("adir", "b")) == 2
 | 
				
			||||||
        assert len(l) == 2
 | 
					        assert len(l) == 2
 | 
				
			||||||
| 
						 | 
					@ -170,7 +170,7 @@ def test_setinitial_conftest_subdirs(testdir, name):
 | 
				
			||||||
    subconftest = sub.ensure("conftest.py")
 | 
					    subconftest = sub.ensure("conftest.py")
 | 
				
			||||||
    conftest = Conftest()
 | 
					    conftest = Conftest()
 | 
				
			||||||
    conftest.setinitial([sub.dirpath(), '--confcutdir=%s' % testdir.tmpdir])
 | 
					    conftest.setinitial([sub.dirpath(), '--confcutdir=%s' % testdir.tmpdir])
 | 
				
			||||||
    if name != ".dotdir":
 | 
					    if name not in ('whatever', '.dotdir'):
 | 
				
			||||||
        assert  subconftest in conftest._conftestpath2mod
 | 
					        assert  subconftest in conftest._conftestpath2mod
 | 
				
			||||||
        assert len(conftest._conftestpath2mod) == 1
 | 
					        assert len(conftest._conftestpath2mod) == 1
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue