From 47df1e16b64174d1fe29dd89355c68b2e52153c7 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 1 Jan 2010 21:03:33 +0100 Subject: [PATCH] fix some failures introduced by the last commit, document new "pytestconfig" funcarg --HG-- branch : trunk --- CHANGELOG | 3 +++ py/plugin/pytest_default.py | 1 + py/plugin/pytest_pytester.py | 4 +++- testing/cmdline/test_cmdline.py | 9 ++++----- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c997782bc..8d4540124 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,9 @@ Changes between 1.X and 1.1.1 - new option: --confcutdir=dir will make py.test only consider conftest files that are relative to the specified dir. +- new funcarg: "pytestconfig" is the pytest config object for access + to command line args and can now be easily used in a test. + - install 'py.test' and `py.which` with a ``-$VERSION`` suffix to disambiguate between Python3, python2.X, Jython and PyPy installed versions. diff --git a/py/plugin/pytest_default.py b/py/plugin/pytest_default.py index e65e7e6c6..d1e6fdcf8 100644 --- a/py/plugin/pytest_default.py +++ b/py/plugin/pytest_default.py @@ -29,6 +29,7 @@ def pytest_collect_file(path, parent): return parent.Module(path, parent=parent) def pytest_funcarg__pytestconfig(request): + """ the pytest config object with access to command line opts.""" return request.config def pytest_collect_directory(path, parent): diff --git a/py/plugin/pytest_pytester.py b/py/plugin/pytest_pytester.py index 18005a03d..89cfd38ce 100644 --- a/py/plugin/pytest_pytester.py +++ b/py/plugin/pytest_pytester.py @@ -338,8 +338,10 @@ class TmpTestdir: def spawn_pytest(self, string, expect_timeout=10.0): pexpect = py.test.importorskip("pexpect", "2.4") + if not self.request.config.getvalue("toolsonpath"): + py.test.skip("need --tools-on-path to run py.test script") basetemp = self.tmpdir.mkdir("pexpect") - invoke = "%s %s" % self._getpybinargs("py.test") + invoke = self._getpybinargs("py.test")[0] cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string) child = pexpect.spawn(cmd, logfile=basetemp.join("spawn.out").open("w")) child.timeout = expect_timeout diff --git a/testing/cmdline/test_cmdline.py b/testing/cmdline/test_cmdline.py index 3de0d5dab..97e723dde 100644 --- a/testing/cmdline/test_cmdline.py +++ b/testing/cmdline/test_cmdline.py @@ -3,14 +3,13 @@ import sys, py pytest_plugins = "pytest_pytester" @py.test.mark.multi(name=[x for x in dir(py.cmdline) if x[0] != "_"]) -def test_cmdmain(name): +def test_cmdmain(name, pytestconfig): main = getattr(py.cmdline, name) assert py.builtin.callable(main) assert name[:2] == "py" - scriptname = "py." + name[2:] - if sys.platform == "win32": - scriptname += ".exe" - assert py.path.local.sysfind(scriptname), scriptname + if pytestconfig.getvalue("toolsonpath"): + scriptname = "py." + name[2:] + assert py.path.local.sysfind(scriptname), scriptname class TestPyLookup: def test_basic(self, testdir):