diff --git a/CHANGELOG b/CHANGELOG index 8471aef39..f26f499ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 1.X and 1.1.1 ===================================== +- new option: --genscript=path will generate a standalone py.test script + which will not need any libraries installed. thanks to Ralf Schmitt. + - new option: --ignore will prevent specified path from collection. Can be specified multiple times. diff --git a/bin-for-dist/generate_standalone_pytest.py b/bin-for-dist/generate_standalone_pytest.py deleted file mode 100755 index 743effb4a..000000000 --- a/bin-for-dist/generate_standalone_pytest.py +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env python - -import os -import cPickle -import zlib -import base64 -import sys - -def main(pybasedir, outfile, infile): - os.chdir(str(pybasedir)) - outfile = str(outfile) - infile = str(infile) - files = [] - for dirpath, dirnames, filenames in os.walk("py"): - for f in filenames: - if not f.endswith(".py"): - continue - - fn = os.path.join(dirpath, f) - files.append(fn) - - name2src = {} - for f in files: - k = f.replace("/", ".")[:-3] - name2src[k] = open(f, "rb").read() - - data = cPickle.dumps(name2src, 2) - data = zlib.compress(data, 9) - data = base64.encodestring(data) - - exe = open(infile, "rb").read() - exe = exe.replace("@SOURCES@", data) - - open(outfile, "wb").write(exe) - os.chmod(outfile, 493) # 0755 - sys.stdout.write("generated %s\n" % outfile) - -if __name__=="__main__": - dn = os.path.dirname - pybasedir = dn(dn(os.path.abspath(__file__))) - outfile = os.path.join(dn(__file__), "py.test") - infile = outfile+"-in" - main(pybasedir, outfile, infile) diff --git a/py/impl/test/pluginmanager.py b/py/impl/test/pluginmanager.py index 28951b24b..89322aac2 100644 --- a/py/impl/test/pluginmanager.py +++ b/py/impl/test/pluginmanager.py @@ -8,7 +8,7 @@ from py.impl.test.outcome import Skipped default_plugins = ( "default runner capture terminal mark skipping tmpdir monkeypatch " - "recwarn pdb pastebin unittest helpconfig nose assertion").split() + "recwarn pdb pastebin unittest helpconfig nose assertion genscript").split() def check_old_use(mod, modname): clsname = modname[len('pytest_'):].capitalize() + "Plugin" diff --git a/py/plugin/pytest_genscript.py b/py/plugin/pytest_genscript.py new file mode 100755 index 000000000..c25ade1bf --- /dev/null +++ b/py/plugin/pytest_genscript.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python + +import os +import zlib +import base64 +import sys +try: + import pickle +except Importerror: + import cPickle as pickle + +def pytest_addoption(parser): + group = parser.getgroup("general") + group.addoption("--genscript", action="store", default=None, + dest="genscript", metavar="path", + help="create standalone py.test script at given target path.") + +def pytest_configure(config): + genscript = config.getvalue("genscript") + if genscript: + import py + mydir = py.path.local(__file__).dirpath() + infile = mydir.join("standalonetemplate.py") + pybasedir = py.path.local(py.__file__).dirpath().dirpath() + main(pybasedir, outfile=genscript, infile=infile) + raise SystemExit(0) + +def main(pybasedir, outfile, infile): + os.chdir(str(pybasedir)) + outfile = str(outfile) + infile = str(infile) + files = [] + for dirpath, dirnames, filenames in os.walk("py"): + for f in filenames: + if not f.endswith(".py"): + continue + + fn = os.path.join(dirpath, f) + files.append(fn) + + name2src = {} + for f in files: + k = f.replace("/", ".")[:-3] + name2src[k] = open(f, "rb").read() + + data = pickle.dumps(name2src, 2) + data = zlib.compress(data, 9) + data = base64.encodestring(data) + + exe = open(infile, "rb").read() + exe = exe.replace("@SOURCES@", data) + + open(outfile, "wb").write(exe) + os.chmod(outfile, 493) # 0755 + sys.stdout.write("generated standalone py.test at %r, have fun!\n" % outfile) + +if __name__=="__main__": + dn = os.path.dirname + here = os.path.abspath(dn(__file__)) # py/plugin/ + pybasedir = dn(dn(here)) + outfile = os.path.join(os.getcwd(), "py.test-standalone") + infile = os.path.join(here, 'standalonetemplate.py') + main(pybasedir, outfile, infile) diff --git a/bin-for-dist/py.test-in b/py/plugin/standalonetemplate.py similarity index 91% rename from bin-for-dist/py.test-in rename to py/plugin/standalonetemplate.py index 18843ff3c..cf1b26d1b 100755 --- a/bin-for-dist/py.test-in +++ b/py/plugin/standalonetemplate.py @@ -12,11 +12,11 @@ if sys.version_info >= (3,0): exec("def do_exec(co, loc): exec(co, loc)\n") import pickle sources = sources.encode("ascii") # ensure bytes + sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) else: import cPickle as pickle exec("def do_exec(co, loc): exec co in loc\n") - -sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) + sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) class DictImporter(object): sources = sources diff --git a/pytest_xmlresult.py b/pytest_xmlresult.py index 66c7a3857..7192559d2 100644 --- a/pytest_xmlresult.py +++ b/pytest_xmlresult.py @@ -8,7 +8,7 @@ import time def pytest_addoption(parser): - group = parser.addgroup("xmlresult", "xmlresult plugin options") + group = parser.getgroup("xmlresult", "xmlresult plugin options") group.addoption('--xmlresult', action="store", dest="xmlresult", metavar="path", default=None, help="path for machine-readable xml result log.") diff --git a/bin-for-dist/test_generate_standalone.py b/testing/plugin/test_pytest_genscript.py similarity index 77% rename from bin-for-dist/test_generate_standalone.py rename to testing/plugin/test_pytest_genscript.py index 2ef62e2c5..ecf6d8023 100644 --- a/bin-for-dist/test_generate_standalone.py +++ b/testing/plugin/test_pytest_genscript.py @@ -1,9 +1,5 @@ import py, os, sys -import generate_standalone_pytest import subprocess -mydir = py.path.local(__file__).dirpath() -pybasedir = mydir.join("..") -assert pybasedir.join("py").check() def pytest_funcarg__standalone(request): return request.cached_setup(scope="module", setup=lambda: Standalone(request)) @@ -11,10 +7,8 @@ def pytest_funcarg__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(pybasedir=pybasedir, - infile=infile, outfile=self.script) + self.testdir.runpytest("--genscript=%s" % self.script) def run(self, anypython, testdir, *args): testdir.chdir()