diff --git a/py/plugin/pytest_genscript.py b/py/plugin/pytest_genscript.py index c25ade1bf..468b71117 100755 --- a/py/plugin/pytest_genscript.py +++ b/py/plugin/pytest_genscript.py @@ -40,7 +40,7 @@ def main(pybasedir, outfile, infile): name2src = {} for f in files: - k = f.replace("/", ".")[:-3] + k = f.replace(os.sep, ".")[:-3] name2src[k] = open(f, "rb").read() data = pickle.dumps(name2src, 2) diff --git a/py/plugin/pytest_pytester.py b/py/plugin/pytest_pytester.py index 89cfd38ce..abe2ebb9a 100644 --- a/py/plugin/pytest_pytester.py +++ b/py/plugin/pytest_pytester.py @@ -69,8 +69,8 @@ class TmpTestdir: self.tmpdir = tmpdir.mkdir(name) self.plugins = [] self._syspathremove = [] - self.chdir() # always chdir - assert hasattr(self, '_olddir') + if not hasattr(request.function, "nochdir"): + self.chdir() # always chdir self.request.addfinalizer(self.finalize) def __repr__(self): @@ -280,12 +280,7 @@ class TmpTestdir: return py.std.subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw) def run(self, *cmdargs): - old = self.tmpdir.chdir() - #print "chdir", self.tmpdir - try: - return self._run(*cmdargs) - finally: - old.chdir() + return self._run(*cmdargs) def _run(self, *cmdargs): cmdargs = [str(x) for x in cmdargs] diff --git a/testing/plugin/test_pytest_genscript.py b/testing/plugin/test_pytest_genscript.py index ecf6d8023..76b1c6c90 100644 --- a/testing/plugin/test_pytest_genscript.py +++ b/testing/plugin/test_pytest_genscript.py @@ -4,11 +4,15 @@ import subprocess def pytest_funcarg__standalone(request): return request.cached_setup(scope="module", setup=lambda: Standalone(request)) +pytestmark = py.test.mark.nochdir + class Standalone: def __init__(self, request): self.testdir = request.getfuncargvalue("testdir") self.script = self.testdir.tmpdir.join("mypytest") - self.testdir.runpytest("--genscript=%s" % self.script) + result = self.testdir.runpytest("--genscript=%s" % self.script) + assert result.ret == 0 + assert self.script.check() def run(self, anypython, testdir, *args): testdir.chdir()