diff --git a/bin-for-dist/test_generate_standalone.py b/bin-for-dist/test_generate_standalone.py index c19fc021a..9e5ac3feb 100644 --- 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*" + ]) diff --git a/py/impl/test/config.py b/py/impl/test/config.py index a434d304b..7ad036bee 100644 --- 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