diff --git a/CHANGELOG b/CHANGELOG index 124c78413..d4126d1a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -50,6 +50,8 @@ Changes between 1.X and 1.1.1 - change: pytest doctest plugin is now enabled by default and has a new option --doctest-glob to set a pattern for file matches. +- change: remove internal py._* helper vars, only keep py._pydir + - robustify capturing to survive if custom pytest_runtest_setup code failed and prevented the capturing setup code from running. diff --git a/bin-for-dist/makepluginlist.py b/bin-for-dist/makepluginlist.py index 0e04ce704..109d5cdb8 100644 --- a/bin-for-dist/makepluginlist.py +++ b/bin-for-dist/makepluginlist.py @@ -128,7 +128,7 @@ class RestWriter: class PluginOverview(RestWriter): def makerest(self, config): - plugindir = py._dir.join('plugin') + plugindir = py._pydir.join('plugin') for cat, specs in plugins: pluginlist = specs.split() self.h1(cat) diff --git a/py/__init__.py b/py/__init__.py index 4239a6825..68afab0ab 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -19,9 +19,7 @@ py.apipkg.initpkg(__name__, dict( # access to all posix errno's as classes error = '.impl.error:error', - _impldir = '.impl._metainfo:impldir', - _dir = '.impl._metainfo:pydir', - _pydirs = '.impl._metainfo:pydirs', + _pydir = '.impl._metainfo:pydir', version = 'py:__version__', # backward compatibility cmdline = { diff --git a/py/impl/_metainfo.py b/py/impl/_metainfo.py index fa720bf1d..12581eb7a 100644 --- a/py/impl/_metainfo.py +++ b/py/impl/_metainfo.py @@ -1,9 +1,2 @@ - import py - pydir = py.path.local(py.__file__).dirpath() -impldir = pydir.join("impl") - -# list of all directories beloging to py -assert impldir.relto(pydir) -pydirs = [pydir] diff --git a/py/impl/test/collect.py b/py/impl/test/collect.py index d547d17e9..a4f76b44d 100644 --- a/py/impl/test/collect.py +++ b/py/impl/test/collect.py @@ -257,7 +257,7 @@ class Collector(Node): path = self.fspath ntraceback = traceback.cut(path=self.fspath) if ntraceback == traceback: - ntraceback = ntraceback.cut(excludepath=py._dir) + ntraceback = ntraceback.cut(excludepath=py._pydir) traceback = ntraceback.filter() return traceback diff --git a/py/impl/test/config.py b/py/impl/test/config.py index aa924fe97..641e01384 100644 --- a/py/impl/test/config.py +++ b/py/impl/test/config.py @@ -269,21 +269,17 @@ class Config(object): def getrsyncdirs(self): config = self - roots = config.option.rsyncdir + candidates = [py._pydir] + config.option.rsyncdir conftestroots = config.getconftest_pathlist("rsyncdirs") if conftestroots: - roots.extend(conftestroots) - pydirs = [x.realpath() for x in py._pydirs] - roots = [py.path.local(root) for root in roots] - for root in roots: + candidates.extend(conftestroots) + roots = [] + for root in candidates: + root = py.path.local(root).realpath() if not root.check(): raise config.Error("rsyncdir doesn't exist: %r" %(root,)) - if pydirs is not None and root.basename in ("py", "_py"): - try: - pydirs.remove(root) # otherwise it's a conflict - except ValueError: # we run as standalone py.test - pass - roots.extend(pydirs) + if root not in roots: + roots.append(root) return roots # diff --git a/py/impl/test/dist/gwmanage.py b/py/impl/test/dist/gwmanage.py index b7822d08e..979a7136f 100644 --- a/py/impl/test/dist/gwmanage.py +++ b/py/impl/test/dist/gwmanage.py @@ -3,7 +3,7 @@ """ import py -import sys, os +import sys, os.path import execnet from execnet.gateway_base import RemoteError @@ -35,7 +35,12 @@ class GatewayManager: gateways = [] for gateway in self.group: spec = gateway.spec - if spec.popen and not spec.chdir and not spec.python: + if spec.popen and not spec.chdir: + # XXX this assumes that sources are python-packages + # and that adding the basedir does not hurt + gateway.remote_exec(""" + import sys ; sys.path.insert(0, %r) + """ % os.path.dirname(str(source))).waitclose() continue if spec not in seen: def finished(): diff --git a/py/impl/test/pycollect.py b/py/impl/test/pycollect.py index d99552938..a599e4d1f 100644 --- a/py/impl/test/pycollect.py +++ b/py/impl/test/pycollect.py @@ -246,7 +246,7 @@ class FunctionMixin(PyobjMixin): if ntraceback == traceback: ntraceback = ntraceback.cut(path=path) if ntraceback == traceback: - ntraceback = ntraceback.cut(excludepath=py._dir) + ntraceback = ntraceback.cut(excludepath=py._pydir) traceback = ntraceback.filter() return traceback diff --git a/py/plugin/pytest_pytester.py b/py/plugin/pytest_pytester.py index 5c1278cda..6cc2b8f73 100644 --- a/py/plugin/pytest_pytester.py +++ b/py/plugin/pytest_pytester.py @@ -318,7 +318,7 @@ class TmpTestdir: assert hasattr(py.cmdline, cmdlinename), cmdlinename source = ("import sys ; sys.path.insert(0, %r); " "import py ; py.cmdline.%s()" % - (str(py._dir.dirpath()), cmdlinename)) + (str(py._pydir.dirpath()), cmdlinename)) return (sys.executable, "-c", source,) def runpython(self, script): @@ -329,7 +329,7 @@ class TmpTestdir: def _getsysprepend(self): if not self.request.config.getvalue("toolsonpath"): - s = "import sys ; sys.path.insert(0, %r) ; " % str(py._dir.dirpath()) + s = "import sys ; sys.path.insert(0, %r) ; " % str(py._pydir.dirpath()) else: s = "" return s diff --git a/py/plugin/pytest_restdoc.py b/py/plugin/pytest_restdoc.py index bce3ecdb1..f9388bd5e 100644 --- a/py/plugin/pytest_restdoc.py +++ b/py/plugin/pytest_restdoc.py @@ -174,7 +174,7 @@ class ReSTSyntaxTest(py.test.collect.Item): 'to the py package') % (text,) relpath = '/'.join(text.split('/')[1:]) if check: - pkgroot = py._impldir + pkgroot = py._pydir abspath = pkgroot.join(relpath) assert pkgroot.join(relpath).check(), ( 'problem with linkrole :source:`%s`: ' diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 29e5ac11d..022d7bf97 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -112,7 +112,7 @@ class TestTraceback_f_g_h: def test_traceback_cut_excludepath(self, testdir): p = testdir.makepyfile("def f(): raise ValueError") excinfo = py.test.raises(ValueError, "p.pyimport().f()") - basedir = py._impldir + basedir = py._pydir newtraceback = excinfo.traceback.cut(excludepath=basedir) assert len(newtraceback) == 1 assert newtraceback[0].frame.code.path == p diff --git a/testing/plugin/test_pytest_default.py b/testing/plugin/test_pytest_default.py index e8c4a3724..c103b3b0b 100644 --- a/testing/plugin/test_pytest_default.py +++ b/testing/plugin/test_pytest_default.py @@ -59,7 +59,7 @@ class TestDistOptions: def test_getrsyncdirs(self, testdir): config = testdir.parseconfigure('--rsyncdir=' + str(testdir.tmpdir)) roots = config.getrsyncdirs() - assert len(roots) == 1 + len(py._pydirs) + assert len(roots) == 1 + 1 # pylib itself assert testdir.tmpdir in roots def test_getrsyncdirs_with_conftest(self, testdir): @@ -71,7 +71,7 @@ class TestDistOptions: """) config = testdir.parseconfigure(testdir.tmpdir, '--rsyncdir=y', '--rsyncdir=z') roots = config.getrsyncdirs() - assert len(roots) == 3 + len(py._pydirs) + assert len(roots) == 3 + 1 # pylib itself assert py.path.local('y') in roots assert py.path.local('z') in roots assert testdir.tmpdir.join('x') in roots diff --git a/testing/pytest/dist/test_gwmanage.py b/testing/pytest/dist/test_gwmanage.py index e07ca0ab5..da4bdee5b 100644 --- a/testing/pytest/dist/test_gwmanage.py +++ b/testing/pytest/dist/test_gwmanage.py @@ -51,12 +51,19 @@ class TestGatewayManagerPopen: hm.makegateways() assert len(hm.group) == 2 for gw in hm.group: - gw.remote_exec = None + class pseudoexec: + args = [] + def __init__(self, *args): + self.args.extend(args) + def waitclose(self): + pass + gw.remote_exec = pseudoexec l = [] hm.rsync(source, notify=lambda *args: l.append(args)) assert not l hm.exit() assert not len(hm.group) + assert "sys.path.insert" in gw.remote_exec.args[0] def test_rsync_popen_with_path(self, hook, mysetup): source, dest = mysetup.source, mysetup.dest diff --git a/testing/pytest/test_outcome.py b/testing/pytest/test_outcome.py index c6f2f8deb..fd1177fd0 100644 --- a/testing/pytest/test_outcome.py +++ b/testing/pytest/test_outcome.py @@ -66,6 +66,6 @@ def test_pytest_cmdline_main(testdir): assert 1 if __name__ == '__main__': py.test.cmdline.main([__file__]) - """ % (str(py._dir.dirpath()))) + """ % (str(py._pydir.dirpath()))) import subprocess subprocess.check_call([sys.executable, str(p)]) diff --git a/testing/test_py_imports.py b/testing/test_py_imports.py index 587837081..28873c317 100644 --- a/testing/test_py_imports.py +++ b/testing/test_py_imports.py @@ -25,7 +25,7 @@ def test_virtual_module_identity(): assert local1 is local2 def test_importall(): - base = py._impldir + base = py._pydir.join("impl") nodirs = [ base.join('test', 'testing', 'data'), base.join('path', 'gateway',),