From a42d9eb9f641b7e6af704964851393ef62a63e66 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 30 Dec 2009 18:11:00 +0100 Subject: [PATCH] fix some standalone-script running issues: * standalone can run standalone tests * exception handling is more careful with assuming valid filenames * bits here and there --HG-- branch : trunk --- bin-for-dist/generate_standalone_pytest.py | 8 ++++---- bin-for-dist/test_generate_standalone.py | 6 ++++-- py/impl/code/code.py | 3 ++- testing/plugin/test_pytest_doctest.py | 17 ++++++++++------- testing/plugin/test_pytest_helpconfig.py | 4 ++-- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/bin-for-dist/generate_standalone_pytest.py b/bin-for-dist/generate_standalone_pytest.py index c46fa505b..743effb4a 100755 --- a/bin-for-dist/generate_standalone_pytest.py +++ b/bin-for-dist/generate_standalone_pytest.py @@ -6,8 +6,8 @@ import zlib import base64 import sys -def main(pydir, outfile, infile): - os.chdir(os.path.dirname(str(pydir))) +def main(pybasedir, outfile, infile): + os.chdir(str(pybasedir)) outfile = str(outfile) infile = str(infile) files = [] @@ -37,7 +37,7 @@ def main(pydir, outfile, infile): if __name__=="__main__": dn = os.path.dirname - pydir = os.path.join(dn(dn(os.path.abspath(__file__))), 'py') + pybasedir = dn(dn(os.path.abspath(__file__))) outfile = os.path.join(dn(__file__), "py.test") infile = outfile+"-in" - main(pydir, outfile, infile) + main(pybasedir, outfile, infile) diff --git a/bin-for-dist/test_generate_standalone.py b/bin-for-dist/test_generate_standalone.py index 9e5ac3feb..2ef62e2c5 100644 --- a/bin-for-dist/test_generate_standalone.py +++ b/bin-for-dist/test_generate_standalone.py @@ -2,6 +2,8 @@ import py, os, sys import generate_standalone_pytest import subprocess mydir = py.path.local(__file__).dirpath() +pybasedir = mydir.join("..") +assert pybasedir.join("py").check() def pytest_funcarg__standalone(request): return request.cached_setup(scope="module", setup=lambda: Standalone(request)) @@ -11,7 +13,7 @@ class Standalone: self.testdir = request.getfuncargvalue("testdir") infile = mydir.join("py.test-in") self.script = self.testdir.tmpdir.join("mypytest") - generate_standalone_pytest.main(pydir=os.path.dirname(py.__file__), + generate_standalone_pytest.main(pybasedir=pybasedir, infile=infile, outfile=self.script) def run(self, anypython, testdir, *args): @@ -34,6 +36,6 @@ def test_rundist(testdir, standalone): """) result = standalone.run(sys.executable, testdir, '-n', '3') assert result.ret == 0 - result.fnmatch_lines([ + result.stdout.fnmatch_lines([ "*1 passed*" ]) diff --git a/py/impl/code/code.py b/py/impl/code/code.py index 0138c6593..9fbd2b41b 100644 --- a/py/impl/code/code.py +++ b/py/impl/code/code.py @@ -537,8 +537,9 @@ class FormattedExcinfo(object): else: if self.style == "short": line = source[line_index].lstrip() + trybasename = getattr(entry.path, 'basename', entry.path) lines.append(' File "%s", line %d, in %s' % ( - entry.path.basename, entry.lineno+1, entry.name)) + trybasename, entry.lineno+1, entry.name)) lines.append(" " + line) if excinfo: lines.extend(self.get_exconly(excinfo, indent=4)) diff --git a/testing/plugin/test_pytest_doctest.py b/testing/plugin/test_pytest_doctest.py index cb9ac4096..9e1c91c60 100644 --- a/testing/plugin/test_pytest_doctest.py +++ b/testing/plugin/test_pytest_doctest.py @@ -1,5 +1,7 @@ from py.plugin.pytest_doctest import DoctestModule, DoctestTextfile +pytest_plugins = ["pytest_doctest"] + class TestDoctests: def test_collect_testtextfile(self, testdir): @@ -12,14 +14,15 @@ class TestDoctests: """) for x in (testdir.tmpdir, checkfile): #print "checking that %s returns custom items" % (x,) - items, reprec = testdir.inline_genitems(x) + items, reprec = testdir.inline_genitems(x, '-p', 'doctest') assert len(items) == 1 assert isinstance(items[0], DoctestTextfile) def test_collect_module(self, testdir): path = testdir.makepyfile(whatever="#") for p in (path, testdir.tmpdir): - items, reprec = testdir.inline_genitems(p, '--doctest-modules') + items, reprec = testdir.inline_genitems(p, '-p', 'doctest', + '--doctest-modules') assert len(items) == 1 assert isinstance(items[0], DoctestModule) @@ -29,7 +32,7 @@ class TestDoctests: >>> x == 1 False """) - reprec = testdir.inline_run(p) + reprec = testdir.inline_run(p, '-p', 'doctest') reprec.assertoutcome(failed=1) def test_doctest_unexpected_exception(self, testdir): @@ -41,7 +44,7 @@ class TestDoctests: >>> x 2 """) - reprec = testdir.inline_run(p) + reprec = testdir.inline_run(p, '-p', 'doctest') call = reprec.getcall("pytest_runtest_logreport") assert call.report.failed assert call.report.longrepr @@ -60,7 +63,7 @@ class TestDoctests: ''' """) - reprec = testdir.inline_run(p, "--doctest-modules") + reprec = testdir.inline_run(p, '-p', 'doctest', "--doctest-modules") reprec.assertoutcome(failed=1) def test_doctestmodule_external(self, testdir): @@ -73,7 +76,7 @@ class TestDoctests: 2 ''' """) - result = testdir.runpytest(p, "--doctest-modules") + result = testdir.runpytest(p, '-p', 'doctest', "--doctest-modules") result.stdout.fnmatch_lines([ '004 *>>> i = 0', '005 *>>> i + 1', @@ -91,7 +94,7 @@ class TestDoctests: >>> i + 1 2 """) - result = testdir.runpytest(p) + result = testdir.runpytest(p, '-p', 'doctest') result.stdout.fnmatch_lines([ '001 >>> i = 0', '002 >>> i + 1', diff --git a/testing/plugin/test_pytest_helpconfig.py b/testing/plugin/test_pytest_helpconfig.py index 6ec2c43aa..51752bce7 100644 --- a/testing/plugin/test_pytest_helpconfig.py +++ b/testing/plugin/test_pytest_helpconfig.py @@ -5,9 +5,9 @@ def test_version(testdir): assert py.version == py.__version__ result = testdir.runpytest("--version") assert result.ret == 0 - p = py.path.local(py.__file__).dirpath() + #p = py.path.local(py.__file__).dirpath() assert result.stderr.fnmatch_lines([ - '*py.test*%s*imported from*%s*' % (py.version, p) + '*py.test*%s*imported from*' % (py.version, ) ]) def test_helpconfig(testdir):