2013-07-26 14:59:31 +08:00
|
|
|
import pytest
|
2013-10-12 21:39:22 +08:00
|
|
|
import sys
|
2009-12-31 00:08:45 +08:00
|
|
|
|
2010-10-10 19:48:49 +08:00
|
|
|
|
2013-07-26 14:59:31 +08:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def standalone(request):
|
|
|
|
return 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):
|
2013-07-26 14:59:31 +08:00
|
|
|
if sys.version_info >= (2,7):
|
|
|
|
result = testdir._run(anypython, "-c",
|
|
|
|
"import sys;print sys.version_info >=(2,7)")
|
|
|
|
if result.stdout.str() == "False":
|
|
|
|
pytest.skip("genscript called from python2.7 cannot work "
|
|
|
|
"earlier python versions")
|
2009-12-31 00:40:50 +08:00
|
|
|
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
|
|
|
])
|