2009-12-31 00:40:50 +08:00
|
|
|
import py, os, sys
|
2009-12-31 00:08:45 +08:00
|
|
|
import subprocess
|
|
|
|
|
2010-10-10 19:48:49 +08:00
|
|
|
|
2009-12-31 00:40:50 +08:00
|
|
|
def pytest_funcarg__standalone(request):
|
2013-02-04 23:07:51 +08:00
|
|
|
return request.cached_setup(scope="module",
|
|
|
|
setup=lambda: Standalone(request))
|
2009-12-31 00:40:50 +08:00
|
|
|
|
|
|
|
class Standalone:
|
|
|
|
def __init__(self, request):
|
|
|
|
self.testdir = request.getfuncargvalue("testdir")
|
2010-01-18 23:48:20 +08:00
|
|
|
script = "mypytest"
|
|
|
|
result = self.testdir.runpytest("--genscript=%s" % script)
|
2010-01-02 04:54:27 +08:00
|
|
|
assert result.ret == 0
|
2010-01-18 23:48:20 +08:00
|
|
|
self.script = self.testdir.tmpdir.join(script)
|
2010-01-02 04:54:27 +08:00
|
|
|
assert self.script.check()
|
2009-12-31 00:40:50 +08:00
|
|
|
|
|
|
|
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, '--version')
|
2009-12-31 00:08:45 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
result.stderr.fnmatch_lines([
|
2010-11-13 18:10:45 +08:00
|
|
|
"*imported from*mypytest*"
|
2009-12-31 00:08:45 +08:00
|
|
|
])
|
2010-10-28 15:29:56 +08:00
|
|
|
p = testdir.makepyfile("def test_func(): assert 0")
|
|
|
|
result = standalone.run(anypython, testdir, p)
|
|
|
|
assert result.ret != 0
|
2009-12-31 00:40:50 +08:00
|
|
|
|
2010-01-13 23:00:33 +08:00
|
|
|
def test_rundist(testdir, pytestconfig, standalone):
|
|
|
|
pytestconfig.pluginmanager.skipifmissing("xdist")
|
2009-12-31 00:40:50 +08:00
|
|
|
testdir.makepyfile("""
|
|
|
|
def test_one():
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
result = standalone.run(sys.executable, testdir, '-n', '3')
|
2010-01-13 23:00:33 +08:00
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines([
|
|
|
|
"*1 passed*",
|
2009-12-31 00:40:50 +08:00
|
|
|
])
|