[py-svn] py-trunk commit f01f6a7caab9: refine tests to cache single-script and make standalone work with distributed testing.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Dec 30 17:41:06 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1262191250 -3600
# Node ID f01f6a7caab924d5800e21acd9911ea0f44f9b6b
# Parent 528f14456c8c6feeb5cd13afbc9bb51b499e9111
refine tests to cache single-script and make standalone work with distributed testing.
--- a/bin-for-dist/test_generate_standalone.py
+++ b/bin-for-dist/test_generate_standalone.py
@@ -1,18 +1,39 @@
-import py, os
+import py, os, sys
import generate_standalone_pytest
import subprocess
mydir = py.path.local(__file__).dirpath()
-def test_gen(testdir, anypython):
- testdir.chdir()
- infile = mydir.join("py.test-in")
- outfile = testdir.tmpdir.join("mypytest")
- generate_standalone_pytest.main(pydir=os.path.dirname(py.__file__),
- infile=infile, outfile=outfile)
- result = testdir._run(anypython, outfile, '-h')
+def pytest_funcarg__standalone(request):
+ 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")
+ self.script = self.testdir.tmpdir.join("mypytest")
+ generate_standalone_pytest.main(pydir=os.path.dirname(py.__file__),
+ infile=infile, outfile=self.script)
+
+ 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
- result = testdir._run(anypython, outfile, '--version')
+ result = standalone.run(anypython, testdir, '--version')
assert result.ret == 0
result.stderr.fnmatch_lines([
"*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*"
+ ])
--- a/py/impl/test/config.py
+++ b/py/impl/test/config.py
@@ -266,7 +266,10 @@ class Config(object):
if not root.check():
raise config.Error("rsyncdir doesn't exist: %r" %(root,))
if pydirs is not None and root.basename in ("py", "_py"):
- pydirs.remove(root) # otherwise it's a conflict
+ try:
+ pydirs.remove(root) # otherwise it's a conflict
+ except ValueError: # we run as standalone py.test
+ pass
roots.extend(pydirs)
return roots
More information about the pytest-commit
mailing list