refine tests to cache single-script and make standalone work with distributed testing.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-12-30 17:40:50 +01:00
parent 94bc770786
commit 6495007aba
2 changed files with 34 additions and 10 deletions

View File

@ -1,18 +1,39 @@
import py, os
import py, os, sys
import generate_standalone_pytest
import subprocess
mydir = py.path.local(__file__).dirpath()
def test_gen(testdir, anypython):
testdir.chdir()
infile = mydir.join("py.test-in")
outfile = testdir.tmpdir.join("mypytest")
generate_standalone_pytest.main(pydir=os.path.dirname(py.__file__),
infile=infile, outfile=outfile)
result = testdir._run(anypython, outfile, '-h')
def pytest_funcarg__standalone(request):
return request.cached_setup(scope="module", setup=lambda: Standalone(request))
class Standalone:
def __init__(self, request):
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__),
infile=infile, outfile=self.script)
def run(self, anypython, testdir, *args):
testdir.chdir()
return testdir._run(anypython, self.script, *args)
def test_gen(testdir, anypython, standalone):
result = standalone.run(anypython, testdir, '-h')
assert result.ret == 0
result = testdir._run(anypython, outfile, '--version')
result = standalone.run(anypython, testdir, '--version')
assert result.ret == 0
result.stderr.fnmatch_lines([
"*imported from*mypytest"
])
def test_rundist(testdir, standalone):
testdir.makepyfile("""
def test_one():
pass
""")
result = standalone.run(sys.executable, testdir, '-n', '3')
assert result.ret == 0
result.fnmatch_lines([
"*1 passed*"
])

View File

@ -266,7 +266,10 @@ class Config(object):
if not root.check():
raise config.Error("rsyncdir doesn't exist: %r" %(root,))
if pydirs is not None and root.basename in ("py", "_py"):
pydirs.remove(root) # otherwise it's a conflict
try:
pydirs.remove(root) # otherwise it's a conflict
except ValueError: # we run as standalone py.test
pass
roots.extend(pydirs)
return roots