refine tests to cache single-script and make standalone work with distributed testing.
--HG-- branch : trunk
This commit is contained in:
parent
94bc770786
commit
6495007aba
|
@ -1,18 +1,39 @@
|
||||||
import py, os
|
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()
|
||||||
|
|
||||||
def test_gen(testdir, anypython):
|
def pytest_funcarg__standalone(request):
|
||||||
testdir.chdir()
|
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")
|
infile = mydir.join("py.test-in")
|
||||||
outfile = 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(pydir=os.path.dirname(py.__file__),
|
||||||
infile=infile, outfile=outfile)
|
infile=infile, outfile=self.script)
|
||||||
result = testdir._run(anypython, outfile, '-h')
|
|
||||||
|
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
|
assert result.ret == 0
|
||||||
result = testdir._run(anypython, outfile, '--version')
|
result = standalone.run(anypython, testdir, '--version')
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stderr.fnmatch_lines([
|
result.stderr.fnmatch_lines([
|
||||||
"*imported from*mypytest"
|
"*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*"
|
||||||
|
])
|
||||||
|
|
|
@ -266,7 +266,10 @@ class Config(object):
|
||||||
if not root.check():
|
if not root.check():
|
||||||
raise config.Error("rsyncdir doesn't exist: %r" %(root,))
|
raise config.Error("rsyncdir doesn't exist: %r" %(root,))
|
||||||
if pydirs is not None and root.basename in ("py", "_py"):
|
if pydirs is not None and root.basename in ("py", "_py"):
|
||||||
|
try:
|
||||||
pydirs.remove(root) # otherwise it's a conflict
|
pydirs.remove(root) # otherwise it's a conflict
|
||||||
|
except ValueError: # we run as standalone py.test
|
||||||
|
pass
|
||||||
roots.extend(pydirs)
|
roots.extend(pydirs)
|
||||||
return roots
|
return roots
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue