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
This commit is contained in:
holger krekel 2009-12-30 18:11:00 +01:00
parent 6495007aba
commit a42d9eb9f6
5 changed files with 22 additions and 16 deletions

View File

@ -6,8 +6,8 @@ import zlib
import base64 import base64
import sys import sys
def main(pydir, outfile, infile): def main(pybasedir, outfile, infile):
os.chdir(os.path.dirname(str(pydir))) os.chdir(str(pybasedir))
outfile = str(outfile) outfile = str(outfile)
infile = str(infile) infile = str(infile)
files = [] files = []
@ -37,7 +37,7 @@ def main(pydir, outfile, infile):
if __name__=="__main__": if __name__=="__main__":
dn = os.path.dirname 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") outfile = os.path.join(dn(__file__), "py.test")
infile = outfile+"-in" infile = outfile+"-in"
main(pydir, outfile, infile) main(pybasedir, outfile, infile)

View File

@ -2,6 +2,8 @@ import py, os, sys
import generate_standalone_pytest import generate_standalone_pytest
import subprocess import subprocess
mydir = py.path.local(__file__).dirpath() mydir = py.path.local(__file__).dirpath()
pybasedir = mydir.join("..")
assert pybasedir.join("py").check()
def pytest_funcarg__standalone(request): def pytest_funcarg__standalone(request):
return request.cached_setup(scope="module", setup=lambda: Standalone(request)) return request.cached_setup(scope="module", setup=lambda: Standalone(request))
@ -11,7 +13,7 @@ class Standalone:
self.testdir = request.getfuncargvalue("testdir") self.testdir = request.getfuncargvalue("testdir")
infile = mydir.join("py.test-in") infile = mydir.join("py.test-in")
self.script = self.testdir.tmpdir.join("mypytest") 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) infile=infile, outfile=self.script)
def run(self, anypython, testdir, *args): def run(self, anypython, testdir, *args):
@ -34,6 +36,6 @@ def test_rundist(testdir, standalone):
""") """)
result = standalone.run(sys.executable, testdir, '-n', '3') result = standalone.run(sys.executable, testdir, '-n', '3')
assert result.ret == 0 assert result.ret == 0
result.fnmatch_lines([ result.stdout.fnmatch_lines([
"*1 passed*" "*1 passed*"
]) ])

View File

@ -537,8 +537,9 @@ class FormattedExcinfo(object):
else: else:
if self.style == "short": if self.style == "short":
line = source[line_index].lstrip() line = source[line_index].lstrip()
trybasename = getattr(entry.path, 'basename', entry.path)
lines.append(' File "%s", line %d, in %s' % ( 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) lines.append(" " + line)
if excinfo: if excinfo:
lines.extend(self.get_exconly(excinfo, indent=4)) lines.extend(self.get_exconly(excinfo, indent=4))

View File

@ -1,5 +1,7 @@
from py.plugin.pytest_doctest import DoctestModule, DoctestTextfile from py.plugin.pytest_doctest import DoctestModule, DoctestTextfile
pytest_plugins = ["pytest_doctest"]
class TestDoctests: class TestDoctests:
def test_collect_testtextfile(self, testdir): def test_collect_testtextfile(self, testdir):
@ -12,14 +14,15 @@ class TestDoctests:
""") """)
for x in (testdir.tmpdir, checkfile): for x in (testdir.tmpdir, checkfile):
#print "checking that %s returns custom items" % (x,) #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 len(items) == 1
assert isinstance(items[0], DoctestTextfile) assert isinstance(items[0], DoctestTextfile)
def test_collect_module(self, testdir): def test_collect_module(self, testdir):
path = testdir.makepyfile(whatever="#") path = testdir.makepyfile(whatever="#")
for p in (path, testdir.tmpdir): 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 len(items) == 1
assert isinstance(items[0], DoctestModule) assert isinstance(items[0], DoctestModule)
@ -29,7 +32,7 @@ class TestDoctests:
>>> x == 1 >>> x == 1
False False
""") """)
reprec = testdir.inline_run(p) reprec = testdir.inline_run(p, '-p', 'doctest')
reprec.assertoutcome(failed=1) reprec.assertoutcome(failed=1)
def test_doctest_unexpected_exception(self, testdir): def test_doctest_unexpected_exception(self, testdir):
@ -41,7 +44,7 @@ class TestDoctests:
>>> x >>> x
2 2
""") """)
reprec = testdir.inline_run(p) reprec = testdir.inline_run(p, '-p', 'doctest')
call = reprec.getcall("pytest_runtest_logreport") call = reprec.getcall("pytest_runtest_logreport")
assert call.report.failed assert call.report.failed
assert call.report.longrepr 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) reprec.assertoutcome(failed=1)
def test_doctestmodule_external(self, testdir): def test_doctestmodule_external(self, testdir):
@ -73,7 +76,7 @@ class TestDoctests:
2 2
''' '''
""") """)
result = testdir.runpytest(p, "--doctest-modules") result = testdir.runpytest(p, '-p', 'doctest', "--doctest-modules")
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
'004 *>>> i = 0', '004 *>>> i = 0',
'005 *>>> i + 1', '005 *>>> i + 1',
@ -91,7 +94,7 @@ class TestDoctests:
>>> i + 1 >>> i + 1
2 2
""") """)
result = testdir.runpytest(p) result = testdir.runpytest(p, '-p', 'doctest')
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
'001 >>> i = 0', '001 >>> i = 0',
'002 >>> i + 1', '002 >>> i + 1',

View File

@ -5,9 +5,9 @@ def test_version(testdir):
assert py.version == py.__version__ assert py.version == py.__version__
result = testdir.runpytest("--version") result = testdir.runpytest("--version")
assert result.ret == 0 assert result.ret == 0
p = py.path.local(py.__file__).dirpath() #p = py.path.local(py.__file__).dirpath()
assert result.stderr.fnmatch_lines([ 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): def test_helpconfig(testdir):