'test --pyargs option with namespace packages (#1567)'

def test_cmdline_python_namespace_package(self, testdir, monkeypatch):

    monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', raising=False)
    search_path = []
    for dirname in ('hello', 'world'):
        d = testdir.mkdir(dirname)
        search_path.append(d)
        ns = d.mkdir('ns_pkg')
        ns.join('__init__.py').write("__import__('pkg_resources').declare_namespace(__name__)")
        lib = ns.mkdir(dirname)
        lib.ensure('__init__.py')
        lib.join('test_{0}.py'.format(dirname)).write('def    test_{0}():    pass\ndef    test_other():pass'.format(dirname))
    def join_pythonpath(*dirs):
        cur = py.std.os.environ.get('PYTHONPATH')
        if cur:
            dirs += (cur,)
        return os.pathsep.join((str(p) for p in dirs))
    monkeypatch.setenv('PYTHONPATH', join_pythonpath(*search_path))
    for p in search_path:
        monkeypatch.syspath_prepend(p)
    result = testdir.runpytest('--pyargs', '-v', 'ns_pkg.hello', 'world/ns_pkg')
    assert (result.ret == 0)
    result.stdout.fnmatch_lines(['*test_hello.py::test_hello*PASSED', '*test_hello.py::test_other*PASSED', '*test_world.py::test_world*PASSED', '*test_world.py::test_other*PASSED', '*4    passed*'])
    result = testdir.runpytest('--pyargs', '-v', 'ns_pkg.world.test_world::test_other')
    assert (result.ret == 0)
    result.stdout.fnmatch_lines(['*test_world.py::test_other*PASSED', '*1    passed*'])
