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):
|
|
|
|
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",
|
2013-12-16 14:19:49 +08:00
|
|
|
"import sys;print (sys.version_info >=(2,7))")
|
|
|
|
assert result.ret == 0
|
2013-07-26 14:59:31 +08:00
|
|
|
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')
|
2015-07-25 19:50:40 +08:00
|
|
|
if result.ret == 2:
|
|
|
|
result.stderr.fnmatch_lines(["*ERROR: setuptools not installed*"])
|
|
|
|
elif result.ret == 0:
|
|
|
|
result.stderr.fnmatch_lines([
|
|
|
|
"*imported from*mypytest*"
|
|
|
|
])
|
|
|
|
p = testdir.makepyfile("def test_func(): assert 0")
|
|
|
|
result = standalone.run(anypython, testdir, p)
|
|
|
|
assert result.ret != 0
|
|
|
|
else:
|
|
|
|
pytest.fail("Unexpected return code")
|
2009-12-31 00:40:50 +08:00
|
|
|
|
2014-08-12 07:03:14 +08:00
|
|
|
|
|
|
|
def test_freeze_includes():
|
|
|
|
"""
|
|
|
|
Smoke test for freeze_includes(), to ensure that it works across all
|
|
|
|
supported python versions.
|
|
|
|
"""
|
|
|
|
includes = pytest.freeze_includes()
|
|
|
|
assert len(includes) > 1
|
|
|
|
assert '_pytest.genscript' in includes
|
|
|
|
|